• Resolved gbever

    (@gbever)


    I would like to disable one of the payment methods I set up through the plugin for a single product. Is something like this possible?

    In my case, I only want ACH for a particular product

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    You can use the filters provided by WooCommerce to accomplish what you want.

    Example:

    add_filter('woocommerce_available_payment_gateways', function($gateways){
        if(is_checkout() && WC()->cart){
            foreach(WC()->cart->get_cart() as $values){
                if(isset($values['data'])){
                    if($values['data']->get_id() === 79){
       					unset($gateways['stripe_ach']);
       					break;
    				}
                }
            }
    
        }
    	return $gateways;
    });

    You will need to replace “79” with your own product ID.

    Thread Starter gbever

    (@gbever)

    Thank you so much for the super fast response. This code seems to work perfectly but it does the opposite of what i need. I only want to show ACH.

    I assume id only need to change:

    $gateways[‘stripe_ach’]

    but Im unsure of what to set that to. Tried a number of variations including cc, credit_card etc.

    • This reply was modified 9 months, 2 weeks ago by gbever.
    Thread Starter gbever

    (@gbever)

    Via experimentation, I was able to figure out that your answer works perfectly with unset($gateways[‘stripe’]);

    Marking this closed and thanks for the great support.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disable Payment Method for Product’ is closed to new replies.