Created
September 14, 2017 22:16
-
-
Save arsalan13nov/fd42229c2f9f22405af467f3e6c83b76 to your computer and use it in GitHub Desktop.
Selectively disable PayPal on Subscription products for WooCommerce
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
/**** Custom Code to remove Paypal Payment method on checkout if cart contains subscription products. ****/ | |
/**** Place the following code at the bottom of theme's functions.php file. ****/ | |
/** | |
* Remove Paypal method from Checkout. | |
* | |
* @param $gateway_list Contains payment methods array. | |
* @return $gateway_list Contains payment methods array. | |
*/ | |
function woocs_filter_gateways( $gateway_list ) | |
{ | |
global $WOOCS; | |
// If any subscription product is added in the cart, remove Paypal Payment method. | |
if( !WC_Subscriptions_Cart::cart_contains_subscription() ) { | |
unset( $gateway_list['paypal'] ); | |
} | |
return $gateway_list; | |
} | |
add_filter('woocommerce_available_payment_gateways', 'woocs_filter_gateways', 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment