好的,所以我正在尝试编写一个过滤器或钩子,它将根据购物车中物品的总量修改购物车的总金额.例如,如果购物车中有三个商品,我想从总订单中扣除20美元.以下是我到目前为止的代码,非常感谢任何帮助!
add_filter('woocommerce_cart_contents_total', 'bundle_deals');
function bundle_deals( $cart_contents_total, $cart_contents_count) {
global $woocommerce;
if ($woocommerce->cart->get_cart()->cart_contents_count <= 3) {
$cart_contents_total = $woocommerce->cart->get_cart()->cart_contents_total - 20.00;
}
return $cart_contents_total;
}
Run Code Online (Sandbox Code Playgroud)