Tho M
Tho M

Reputation: 23

Change payment gateway option based on cart total in Woocommerce checkout

For my woocommerce shop, i have this filter in functions.php. It force 3DS with "woocommerce Stripe Gateway" plugin.

add_filter('wc_stripe_require_3ds','__return_true');

It work great.

I would like this filter to be active only for order over 50€.

I tried with this but it doesn't work, the order is validated without 3DS.

    $minsecure = 50;
    $order = new WC_Order( $order_id );
    $total = $order->get_total();

    if($total>$minsecure) { 
          add_filter('wc_stripe_require_3ds','__return_true');
    }

I also try to get the cart amount instead of the order amount, but I don't know which one to get for the filter to be active between the time of the "order" click and the confirmation page.

Any help is appreciated.

Upvotes: 2

Views: 504

Answers (1)

jjj
jjj

Reputation: 1005

I would go for this to check if the price of the order is over 50

if( WC()->cart->subtotal > 50 )

So the snippet would look like

add_action('woocommerce_cart_updated', 'wc_stripe_require_3ds', 90);
function wc_stripe_require_3ds ( $cart ){
    if( WC()->cart->subtotal > 50 ) {
        add_filter('wc_stripe_require_3ds','__return_true');
    }
}

Have a try.

Upvotes: 1

Related Questions