PHPWooCommerceWordPress

How to display available payment gateways for your WooCommerce website

0
1.4k
2018 / 04 / 30
$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');

 

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks