Support » Plugin: WooCommerce » Filtering payment gateways

  • Hi,

    I am trying to filter payment gateways depending on choosen shipping method. I have tried this filter, but it does not work:

    add_filter( 'woocommerce_available_payment_gateways', 'hide_unrelated_gateways');
    function hide_unrelated_gateways ($available_gateways) {
    	if( isset( $available_methods['local_delivery']) OR isset( $available_methods['international_delivery'] ) ) {
    		unset($available_gateways['cheque'] );
    	if( isset( $available_methods['local_pickup'])) {
    		unset($available_gateways['cod'] );
        return $available_gateways;

    I am new to WordPress and PHP, so can anybody help me, please?

    Many thanks from Alex

Viewing 13 replies - 1 through 13 (of 13 total)
  • @zed28 You can use APG SHIPPING plugin to filter Payment Gateways based on Shipping method. It works with 2.1 onwards only (not with older versions). Give it a try and let me know if you have a problem setting it up.

    Hi, Chirag Vora,

    thank you for you reply, but unfortunatelly I am using version 2.0.20.


    In that case, you can download and use the old version of the same plugin from github by seeing the changelog. I used it therefore I’m confident that it does work.


    What I want to do is disable paypal if flat rate option is selected. How can I do that?


    @Dalidr APG Shipping has as option to enable only a particular payment gateway for a given shipping method. But you will have to setup a flat rate with that plugin instead of WooCommerce flat rate.

    Give it a try in sandbox first and see how it works out for you.

    @chirag it didn’t work. Are you sure that it works? I enabled the plugin and it doesn’t appear in the shipping options at all. Any idea?

    Not sure why that is happening with your setup. It works fine for me.

    Thanks Chirag.
    Do I have to fill in anything in the settings of AGP?

    As you can see on the images there is not the option AGP.

    Any idea would be much appreciated!

    Hi, Dalibr,

    Plugin did not work for me too (I do not know why…).
    finally, I figured out this problem using simple filter/function:

    add_filter( ‘woocommerce_available_payment_gateways’, ‘hide_unrelated_gateways’);

    function hide_unrelated_gateways ($available_gateways) {
    global $woocommerce;
    if( ($woocommerce->session->chosen_shipping_method == ‘international_delivery’) OR ($woocommerce->session->chosen_shipping_method == ‘local_delivery’)) {
    unset($available_gateways[‘cheque’] );

    if( ($woocommerce->session->chosen_shipping_method == ‘local_pickup’)) {
    unset($available_gateways[‘cod’] );

    return $available_gateways;

    It simply unsets (hides) unwanted gateways. Replace conditions with your own. Hope it helps.


    Hi Alex,

    Thank you, it looks promising. I copied it into functions.php but it doesn’t work, where did you put it?

    Place it in you functions.php.

    You need to replace conditions in filter/function with your own.

    If you look at my code, you can see that for my purpose I am hidding “cheque” gateway when user choose “international delivery” or “local delivery” shipping, etc.

    You need to replace my conditions with your own. Then it will work for you.

    APG Shipping 1.4.1 released today fixes the payment gateway bug. Now payment gateways are filtered correctly.

    Great thank you guys so much!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Filtering payment gateways’ is closed to new replies.