Home Woocommerce cart modifications being overwritten by checkout.js
Reply: 0

Woocommerce cart modifications being overwritten by checkout.js

user1384 Published in June 19, 2018, 4:13 pm

I'm hooking into Woocommerce's woocommerce_calculate_totals to set a minimum order amount for age verification. Basically the customer needs to have an order minimum of $1. This works on the view cart page, but the subtotal is getting overwritten by checkout.js - I can see it being modified after page load.

Here's my code in functions.php:

function hv_set_min_total() {
    if( is_checkout() ) {
        global $woocommerce;
        // set minimum cart total
        $min_cart_total = 1;

        // Total used before taxes and shipping
        $total = $woocommerce->cart->subtotal;

        // compare values
        if( $total < $min_cart_total ) {
            $diff = $min_cart_total - $total;
            $woocommerce->cart->subtotal += $diff;
            $woocommerce->cart->cart_contents_total += $diff;
            $woocommerce->cart->subtotal_ex_tax += $diff;
add_action( 'woocommerce_calculate_totals', 'hv_set_min_total' );

I've also tried hooking into various other hooks that all change the subtotal, but still get overwritten by the checkout.js file. Any ideas on how I can stop this from happening?

Other things I've tried, but still get removed:

  • Add Fee
  • Negative discount
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313035 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO