How to display available payment gateways for your WooCommerce website

display available payment gateways for your WooCommerce website
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$gateways = WC()->payment_gateways->get_available_payment_gateways();
$enabled_gateways = [];
if( $gateways ) {
    foreach( $gateways as $gateway ) {
        if( $gateway->enabled == 'yes' ) {
            $enabled_gateways[] = $gateway;
        }
    }
}
echo '<pre>';
print_r( $enabled_gateways ); // Should return an array of enabled gateways
echo '</pre>';

 

The name of gateway is stored in:

[id] =>

Disable or Enable payment gateways:

 

function filter_gateways($gateways){
  global $woocommerce;
    $thewinner = rand(1,10);
    if ($thewinner == 1 ) {
        unset($gateways['authorize_net_aim_emulation');
    }else{
        unset($gateways['authorize_net_aim_echeck']);
        unset($gateways['authorize_net_aim']);
    }
    return $gateways;
}
add_filter('woocommerce_available_payment_gateways','filter_gateways');

 

Related Posts