我想在用户购买了一定数量的产品后更改woocommerce购物车总数。我根据Change Cart total price in WooCommerce编写了自己的代码:
add_filter('woocommerce_cart_total', 'six_boxsets');
function six_boxsets($wc_price){
//count how many items user has purchased and when it meets 6,change the total price to 999.
$itemcount = WC()->cart->cart_contents_count;
$product_cart_id = WC()->cart->generate_cart_id( '40877' );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
if ($itemcount == '6' && !$in_cart) {
echo "<span style='color:red;'>promotion-</span> ";
$new_total = '999';
return wc_price($new_total);
}else{
return $wc_price;
}
}
在购物车页面和结帐页面上都可以正常工作。但是提交结帐表格并转到付款网关后,它仍然是旧的购物车总数,而不是我所调整的购物车总数。
在我的付款网关中,我使用$order->get_total();
来获取订单价格。
真的迷路了,有人能对此有所启发吗?
THX。
顺便说一句,我仍在使用woocommerce 2.6版本,该版本对我来说很好用。