首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用筛选器或挂钩修改购物车总额

使用筛选器或挂钩修改购物车总额
EN

Stack Overflow用户
提问于 2015-03-15 06:13:34
回答 2查看 14.7K关注 0票数 6

好的,我正在尝试编写一个过滤器或钩子,它将根据购物车中商品的总数量修改购物车的总数量。例如,如果购物车中有三种商品,我想从总订单中扣除20美元。下面是我到目前为止的代码,任何帮助都是非常感谢的!

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-20 15:34:46

代码语言:javascript
复制
function woocommerce_cart_subtotal(  $cart_subtotal, $compound, $obj  ){

$t = 0;
foreach ( $obj->cart_contents as $key => $product ) : 

    $product_price = $product['line_total'];    

    foreach ( WC()->cart->get_coupons( 'order' ) as $code => $coupon ) : 

            $product_price  = 19;//wpq_9522_discount( $product['line_total'], $coupon->discount_type, $coupon->amount ); 

    endforeach; 

    $t += $product_price;

endforeach; 

return $cart_subtotal;//( $t > 0 ) ? sprintf( '<s>%s</s> %s',      
$cart_subtotal, wc_price( $t ) ) : $cart_subtotal ;
}

add_filter( 'woocommerce_cart_subtotal', 'woocommerce_cart_subtotal',      99, 3 );
票数 1
EN

Stack Overflow用户

发布于 2015-03-20 16:50:49

总金额可以从以下钩子更改。

代码语言:javascript
复制
add_action('woocommerce_calculate_totals', array($this, 'calculate_totals'), 10, 1);

function calculate_totals($totals){
//your code
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29054877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档