Woocommerce: How can I use Stripe ONLY for subscriptions? I want to turn it off for regular product purchases

StackOverflow https://stackoverflow.com/questions/23120782

문제

I am using the Mijireh extension for checkout on my site in order to maintain PCI Compliance. However, Mijireh doesn't support subscriptions, so for subscriptions, I would like to use Stripe. I added in the extension, but now when a user tries to checkout with non-subscription products, it shows two options to pay, Mijireh and Stripe.

How can I have Stripe to be used only for subscriptions and to not have that be an option otherwise?

www.mijireh.com/integrations/woocommerce/

도움이 되었습니까?

해결책

You need to check if the cart or order contains a subscription product, and when it doesn't, remove Stripe from the available payment gateways.

Something like this should be enough to get it working (untested but has all the right moving parts):

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 );

Customised from this gist.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top