小编Rus*_*ers的帖子

使用过滤器或挂钩修改购物车总金额

好的,所以我正在尝试编写一个过滤器或钩子,它将根据购物车中物品的总量修改购物车的总金额.例如,如果购物车中有三个商品,我想从总订单中扣除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)

php wordpress woocommerce

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×1

woocommerce ×1

wordpress ×1