Created
May 5, 2017 13:50
-
-
Save kreamweb/30ce71a9cc23ad6bd7a74679d1c154e9 to your computer and use it in GitHub Desktop.
Only Payapal at checkout
This file contains hidden or 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
| <?php | |
| /** | |
| * Leave only Paypal, if there is a product with subscription on cart | |
| */ | |
| function ywsbs_only_paypal_for_subscriptions( $gateways ) { | |
| if ( yith_added_product_as_subscription_on_cart() ) { | |
| foreach ( $gateways as $k => $gateway ) { | |
| if ( false === strpos( $gateway, 'WC_Gateway_Paypal' ) ) { | |
| unset( $gateways[ $k ] ); | |
| } | |
| } | |
| } | |
| return $gateways; | |
| } | |
| add_filter( 'woocommerce_payment_gateways', 'ywsbs_only_paypal_for_subscriptions' ); | |
| /** | |
| * Checks if there is a product with subscription on cart | |
| */ | |
| function yith_added_product_as_subscription_on_cart() { | |
| if ( ! class_exists( 'YITH_WC_Subscription' ) || empty( WC()->cart ) ) { | |
| return false; | |
| } | |
| foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
| $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
| if ( $_product && YITH_WC_Subscription()->is_subscription( $_product ) ) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment