如果优惠券金额高于购物车小计,还要减少运费总额
该代码应该检查固定优惠券金额是否大于购物车小计。如果是,请从运费总额中减去剩余价格。它在我的函数文件中。
add_filter('woocommerce_package_rates', 'custom_shipping_costs', 10, 2 );
function custom_shipping_costs( $rates, $package ){
//get the shipping total, cart subtotal and coupon amount
$dostava = $cart->shipping_total;
$iznos = $woocommerce->cart->get_cart_subtotal();
$kuponi = $woocommerce->cart->discount_total;
//subtract the coupon amount from cart subtotal
$razlika = $iznos - $kuponi;
//now check if it's higher than what's in the cart, if yes, set the new shipping costs
if($razlika < 0){
$novadostava = $dostava - $razlika;
$cart->shipping_total = $novadostava;
}
return $rates;
}
不幸的是..它不起作用。有什么建议吗?
The code is supposed to check if the fixed coupon amount is bigger than cart subtotals. If yes, subtract the remainder of the price from shipping totals. It's in my functions file.
add_filter('woocommerce_package_rates', 'custom_shipping_costs', 10, 2 );
function custom_shipping_costs( $rates, $package ){
//get the shipping total, cart subtotal and coupon amount
$dostava = $cart->shipping_total;
$iznos = $woocommerce->cart->get_cart_subtotal();
$kuponi = $woocommerce->cart->discount_total;
//subtract the coupon amount from cart subtotal
$razlika = $iznos - $kuponi;
//now check if it's higher than what's in the cart, if yes, set the new shipping costs
if($razlika < 0){
$novadostava = $dostava - $razlika;
$cart->shipping_total = $novadostava;
}
return $rates;
}
Unfortunately.. it doesn't work. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个示例,因为如果必须定义等,则需要考虑更多税率、运输方法等,但当前示例可以正常工作
我们有售价 18 美元的产品和折扣 20 美元的优惠券,运费税 15 美元,最后我们总共得到 13 美元 - https ://prnt.sc/365xV2BWx2wA
Here is an example since there are more to consider to it as taxes rates shipping methods if must define etc but current example works as it
We have product that cost 18$ and coupon that discount 20$ with shipping tax 15$ at the end we get 13$ total - https://prnt.sc/365xV2BWx2wA