Last active
May 15, 2019 00:14
-
-
Save NickGreen/fde2b1bd84ad9c0331998f0c5b6a9f87 to your computer and use it in GitHub Desktop.
Deactivate PayPal standard for non-subscription purchases
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 | |
function deactivate_paypal_unless_subscription( $available_gateways ) { | |
global $wp; | |
if ( class_exists( 'WC_Subscriptions_Cart' ) ) { | |
// version 1.5 and 2.0 compatibility | |
$cart_contains_renewal = function_exists( 'wcs_cart_contains_renewal' ) ? wcs_cart_contains_renewal() : WC_Subscriptions_Cart::cart_contains_subscription_renewal(); | |
if ( is_checkout_pay_page() ) { | |
$order_contains_renewal = function_exists( 'wcs_order_contains_subscription' ) ? wcs_order_contains_subscription( $wp->query_vars['order-pay'] ) : WC_Subscriptions_Order::order_contains_subscription( $wp->query_vars['order-pay'] ); | |
} else { | |
$order_contains_renewal = false; | |
} | |
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() || ! $cart_contains_renewal || ! $order_contains_renewal || ! WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) { | |
if ( isset( $available_gateways['paypal'] ) ) { | |
unset( $available_gateways['paypal'] ); | |
} | |
} | |
} else { | |
if ( isset( $available_gateways['paypal'] ) ) { | |
unset( $available_gateways['paypal'] ); | |
} | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'deactivate_paypal_unless_subscription', 11 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment