WooCommerce cart amount is 0, order without payment!

In some systems built by WooCommerce, the amount of the order will sometimes be 0, such as free products, free samples, the total amount of the cart is 0 after using a coupon, etc. By default, WooCommerce still needs to pay a little bit to generate an order for subsequent processing.

When the shopping cart amount is 0, if the online payment gateway is selected by default, these payment gateways usually report an error because the payment amount is 0, resulting in payment failure. In fact, when the amount is 0, WooCommerce can place an order directly without payment.

WooCommerce Payment Free Direct Order Code

In the following code, we use woocommerce_cart_needs_payment as a Filter for $need_payment parameter, when the order amount is 0, set this parameter to 0, so that the payment button in the shopping cart will be changed to an order button, click on this order button, you can directly order without payment.

add_filter( 'woocommerce_cart_needs_payment', function($need_payment, $cart){
    if($cart->get_total('edit') == 0){
        $need_payment = false;
    }

    return $need_payment;
}, 10,2);

In addition to the shopping cart is 0, free payment order, in some booking systems, inquiry system, also need to pay directly to order, we refer to the above code, modify the $need_payment The parameter is false, the implementation code can be adjusted according to the actual situation.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *