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.
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.