[英]Can't change WooCommerce cart total
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. $cart->total
总是返回 0 并且它低于小计。 I've also tried $cart->cart_contents_total
, it returns proper value but i cant change it.我也试过
$cart->cart_contents_total
,它返回正确的值,但我不能改变它。 WP version is 5.3.2 and WC is 3.8.1. WP 版本是 5.3.2,WC 是 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.