要为woocommerce中的我的额外产品(Monofin-pro)和(Monofin-Jr)或附加产品设置权重,并在购物车中自动计算国家/地区的权重。下面是我要编辑以对我有用的代码。需要您的帮助。
我为此使用了 woocommerce 额外产品插件
/**Extra Product Option Weight*/
add_action( 'woocommerce_before_calculate_totals','add_custom_weight',10,1 );
function add_custom_weight($cart) {
if (is_admin() && ! defined('DOING_AJAX'))
return;
if (did_action('woocommerce_before_calculate_totals') >= 2)
return;
foreach ( $cart->get_cart() as $cart_item ) {
$cart_item['data']->set_weight( 4.170 );
}
}
以上代码为购物车中的每种产品增加了4.170千克的重量。我只想将其用于其他产品Monofin-Pro和Monofin-Jr。