基于“结帐和购物车页面中的 woocommerce 更改价格”答案代码更改结帐页面中的总价,我添加了一些额外的代码来计算用户在购物车中拥有的产品,如果用户在购物车中有 9 种产品然后添加一些总价:
add_action( 'woocommerce_before_cart_totals', 'custom_cart_total' , 'get_cart_contents_count');
function custom_cart_total() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if (WC()->cart->get_cart_contents_count() == 9){
WC()->cart->total += 15;
}
elseif(WC()->cart->get_cart_contents_count() == 6){
WC()->cart->total += 14;
}
elseif(WC()->cart->get_cart_contents_count() == 4){
WC()->cart->total += 13;
}
}
但它不起作用。这张图片将解释一切:
如果有人可以更正代码并告诉我如何显示图片中的消息,我将不胜感激