这是您的购物车数据
global $woocommerce;<br>
$data = $woocommerce->cart->get_cart();<br><br>
<br>
$product_id = array();<br>
$product_weigth = array();<br>
$weight_total = 0;<br>
<br>
破坏您的购物车数据
foreach($data as $value)<br>
{<br>
$product_id[] = $value['product_id'];<br>
}<br>
<br>
for($i=0;$i < count($product_id);$i++)<br>
{<br>
$product_weigth[] = get_post_meta($product_id[$i],'_weight',true);<br>
$weight_total += get_post_meta($product_id[$i],'_weight',true);<br>
}<br><br>
<br>
打印您的购物车产品 ID
print_r($product_id);<br><br>
打印您的购物车产品重量
print_r($product_weigth);<br><br>
总重量
echo $weight_total;<br><br>
添加费用
$woocommerce->cart->add_fee('Shipping Charges(Weight)'.$weight_total, $your_fee, true, 'standard' );<br><br>
现在您可以按重量设置费用.. if - else 条件