Last active
January 16, 2017 12:07
-
-
Save MindyPostoff/2876865d7b1a08346878 to your computer and use it in GitHub Desktop.
Disable PayPal in WooCommerce Checkout for Certain Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Disable PayPal payment method in the checkout if certain | |
* products are present in the cart. | |
* | |
* Add this to your theme's functions.php file | |
*/ | |
add_filter( 'woocommerce_available_payment_gateways', 'filter_gateways', 1); | |
function filter_gateways( $gateways ){ | |
global $woocommerce; | |
foreach ($woocommerce->cart->cart_contents as $key => $values ) { | |
// store product IDs in array PayPal method is disabled at checkout | |
$nonPPproducts = array(1111,2222,3333); // LIST YOUR PRODUCTS HERE | |
if ( in_array( $values['product_id'], $nonPPproducts ) ) { | |
unset($gateways['paypal']); | |
// You can unset other gateways using the gateway ID e.g. "cod", "bacs", "stripe" | |
break; | |
} | |
} | |
return $gateways; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this doesnt work . if you make a failed payment and try pay again , paypal will be shown in available payment gateway