Reputation: 55
add_action( 'woocommerce_calculate_totals', 'woocommerce_calculate_total', 10, 1 );
function woocommerce_calculate_total( $cart ) {
if($cart->subtotal < 300){
$cart->subtotal += 85;
$cart->total += 85;
}
}
This piece of code seems to work fine but only for subtotals. $cart->total
always returns 0 no matter what and its lower than subtotal. I've also tried $cart->cart_contents_total
, it returns proper value but i cant change it.
WP version is 5.3.2 and WC is 3.8.1.
Upvotes: 0
Views: 824
Reputation: 595
You can use:
add_action( 'woocommerce_after_calculate_totals', 'woocommerce_after_calculate_totals', 30 );
function woocommerce_after_calculate_totals( $cart ) {
if($cart->subtotal < 300){
$cart->subtotal += 85;
$cart->total += 85;
}
}
Upvotes: 2