Reputation: 23
I am trying to disable Stripe for subscription payments and show it for ONLY single payments, as in one time payments only.
I came across the below code, but this does the opposite. I need it doing so it hides for subscriptions and shows for single payments (one time payments)
function so23120782_maybe_remove_stripe( $available_gateways ) {
if ( class_exists( 'WC_Subscriptions_Cart' ) && ( ! WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && ! WC_Subscriptions_Order::order_contains_subscription( $_GET['order_id'] ) ) ) ) {
if ( isset( $available_gateways['stripe'] ) ) {
unset( $available_gateways['stripe'] );
}
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'so23120782_maybe_remove_stripe', 11 );
Upvotes: 2
Views: 184
Reputation: 2027
Maybe just change the condition when to unset stripe:
if ( class_exists( 'WC_Subscriptions_Cart' ) && ( WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && WC_Subscriptions_Order::order_contains_subscription( $_GET['order_id'] ) ) ) ) {
(I have removed the "not" -- ! -- from the conditions, which should be fine)
Upvotes: 1