【发布时间】:2022-01-26 21:08:54
【问题描述】:
在 WooCommerce 中,我正在尝试根据购物车重量添加额外的运费。
- 第一个
1500g的费用为 50 美元。 - 在
1500g之上,我们以 1000g 为增量在最初的 50 美元基础上加 10 美元
例如:
- 如果购物车重量为 700 克,我们将加收 50 美元的费用,
- 如果购物车重量为 2600 克,我们将加收 70 美元(50 美元 + 10 美元 +10 美元)的费用……
我卡在计算上:
function weight_add_cart_fee() {
$feeaddtocart = get_option('feeaddtocart');
$customweight = get_option('customweight');
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$cart_weight = WC()->cart->get_cart_contents_weight();
if ($cart_weight <= 500 ) {
$get_cart_total = $woocommerce->cart->get_cart_total();
$newtotal = $get_cart_total + 50;
WC()->cart->add_fee( __('Extra charge (weight): ', 'your_theme_slug'), $newtotal, false );
}
}
我怎样才能做到这一点?任何帮助表示赞赏。
【问题讨论】:
标签: php wordpress woocommerce cart fee