Home » WooCommerce: Force Cart to Specific Amount (Deposit)

WooCommerce: Force Cart to Specific Amount (Deposit)

by Tutor Aspire

Here’s a very simple snippet that achieves a very complex task – what if you wanted to force your Cart to charge a deposit or a fixed fee, no matter the product price?

Well, thankfully WooCommerce is pretty flexible and a lot of workarounds can be found. In this case, forcing the checkout to a fixed amount (e.g. $100) is as simple as applying a negative “cart fee” to make the total become $100.

Sounds like Japanese? Great – here’s why you’re on Business Bloomer. Copy the snippet, apply it to your test WooCommerce site and see the magic happen – without knowing anything about coding!

WooCommerce: force cart amount

PHP Snippet: Force Cart to Specific Amount (Deposit) – WooCommerce

 

/**
* @snippet Force Cart to Specific Amount (Deposit) - WooCommerce
* @how-to Get tutoraspire.com FREE
* @sourcecode https://tutoraspire.com/?p=72625
* @author Tutor Aspire
* @testedwith WooCommerce 3.5.1
*/

// Note: this will force Cart to $100

add_action( 'woocommerce_cart_calculate_fees','tutoraspire_force_cart_to_100' );

function tutoraspire_force_cart_to_100() {
    $total_minus_100 = WC()->cart->get_cart_contents_total() - 100;
    WC()->cart->add_fee( 'Adjustment', $total_minus_100 * -1 );
}

You may also like