• Resolved jurijsmsk

    (@jurijsmsk)


    Hey.

    How to disable stripe gateway for specific ID’s or whole shipping class?

    add_filter( 'woocommerce_available_payment_gateways', 'disable_stripe_for_specific_product_ids' );

    function disable_stripe_for_specific_product_ids( $available_gateways ) {
    if ( is_admin() ) return $available_gateways;

    $specific_product_ids = array(6695, 6627...);

    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $product_id = $cart_item['product_id'];

    if ( in_array( $product_id, $specific_product_ids ) ) {
    unset( $available_gateways['stripe'] );
    break;
    }
    }

    return $available_gateways;
    }

    or

    $specific_shipping_class = 'xl';
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    You would just add this:

    unset( $available_gateways['ppcp'] ); 

    The gateway’s ID is ppcp.

    Thread Starter jurijsmsk

    (@jurijsmsk)

    Still appears even if targeting ID’s… Mhm..

    add_filter('woocommerce_available_payment_gateways', 'disable_ppcp_for_specific_product_ids');

    function disable_ppcp_for_specific_product_ids($available_gateways) {
    if (is_admin()) return $available_gateways;

    $specific_product_ids = array(6695, 6627, so on...);

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
    $product_id = $cart_item['product_id'];

    if (in_array($product_id, $specific_product_ids)) {
    unset($available_gateways['ppcp']);
    break;
    }
    }

    return $available_gateways;
    }
    Plugin Author Payment Plugins

    (@mrclayton)

    Whoops, I see you’re asking about Stripe and I replied with our PayPal plugin’s gateway ID. The Stripe plugin’s gateway naming convention is stripe_${id}. Here are a few examples:

    stripe_cc
    stripe_applepay
    stripe_googlepay
    stripe_ideal

    You can either selectively target the gateways or write code that unsets all array entries that match stripe_.

    Thanks

    Thread Starter jurijsmsk

    (@jurijsmsk)

    If anyone req similar solution.

    add_filter('woocommerce_available_payment_gateways', 'disable_stripe_gateways_for_specific_products');

    function disable_stripe_gateways_for_specific_products($available_gateways) {
    if (is_admin()) return $available_gateways;

    $specific_product_ids = array(123, 1234); //add ur own product id's here

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
    $product_id = $cart_item['product_id'];

    if (in_array($product_id, $specific_product_ids)) {

    foreach ($available_gateways as $gateway_id => $gateway) {
    if (strpos($gateway_id, 'stripe_') === 0) {
    unset($available_gateways[$gateway_id]);
    }
    }
    break;
    }
    }

    return $available_gateways;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to disable stripe gateway for specific ID’s or shipping classes’ is closed to new replies.