Menu Close

WooCommerce: Force Cart to Specific Amount (Deposit)

default

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 total to $100 no matter what is added to cart

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

/**
 * @snippet       WooCommerce Deposit
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// Note: this will force Cart to $100

add_action( 'woocommerce_cart_calculate_fees','bbloomer_woocommerce_deposit' );

function bbloomer_woocommerce_deposit() {
    $total_minus_100 = WC()->cart->get_cart_contents_total() - 100;
    WC()->cart->add_fee( 'Balance', $total_minus_100 * -1 );
}
View Source
Posted in WooCommerce Tips