It’s a very broad question, but my approach would look something like this:
I’d replace your code with this:
<?php my_the_payment_options(); ?>
And then in my plugin:
function my_the_payment_options() {
$payment_options = get_my_available_payment_options();
if ( $payment_options ) :
?>
<div class="payments-options">
<?php foreach ( $payment_options as $k => $v ) call_user_func( $v['callback'] ); ?>
</div>
<?php
endif;
}
function get_my_available_payment_options() {
return apply_filters( 'get_my_available_payment_options', array() );
}
and then in code adding payment method (here for PayPal):
function my_add_paypal( $available_payments ) {
$available_payments[ 'paypal' ] => array(
'callback' => 'my_paypal_callback',
// some other params if needed
);
}
add_filter( 'get_my_available_payment_options', 'my_add_paypal' );
function my_paypal_callback() {
?>
<div class="paypal-div"></div>
<?php
}
Disclaimer: Treat this code as way to show the idea and not as working solution 🙂