提前道歉,因为我刚刚选择了WooCommerce。
早些时候,我在整个行动中写下了我的整个逻辑'woocommerce_before_calculate_totals',如下所示:
add_action('woocommerce_before_calculate_totals', array($this,'calculate_total_price_of_cart'), 10, 1);
function calculate_total_price_of_cart($p_cart_obj){
$p_cart = $p_cart_obj->get_cart();
//code to extract info and add into the cart
$discount_total = fetch_discount_amount($p_cart); //calls helper function and get amount to be discounted
//code to update the cart for discount
$p_cart->discount_total = $discount_total;//this doesn't work
}
以上不起作用。
我认为另一个解决方案是使用过滤器'woocommerce_cart_total_discount'来改变折扣价,如下所示,但它不起作用:
add_filter('woocommerce_cart_total_discount', array($this,'apply_custom_discount'));
function mitte_woocommerce_cart_total_discount($total_discount, $instance)
{
//some code
return $custom_discount;
}
再一次,感谢您的帮助,因为我被困住了,找不到任何资源来解决这个问题。