我正在尝试找到一个功能,如果其中的产品高度超过 2,9 厘米,它会自动向购物车添加费用。
我将 Woocommerce 用于我们简单的非营利漫画书店。我们在瑞典使用基于重量的运输作为标准,如果某件物品超过 3 厘米,则会收取大量费用。
我已经尝试修改LoicTheAztec关于基于购物车总重量的费用的答案,但我真的不知道我在做什么,因为我在保存代码后得到一个空白页。
我要修改的代码是这样的:
add_action( 'woocommerce_cart_calculate_fees', 'shipping_weight_fee', 30, 1 );
function shipping_weight_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Convert cart weight in grams
$cart_weight = $cart->get_cart_contents_weight() * 1000;
$fee = 50; // Starting Fee below 500g
// Above 500g we add $10 to the initial fee by steps of 1000g
if( $cart_weight > 1500 ){
for( $i = 1500; $i < $cart_weight; $i += 1000 ){
$fee += 10;
}
}
// Setting the calculated fee based on weight
$cart->add_fee( __( 'Weight shipping fee' ), $fee, false );
}
我对 php 的体验不仅仅是能够将操作粘贴到我的子主题的 functions.php 中。
我很感激我能得到的任何帮助。