我在我的eCommerce站点上使用woocommerce插件v2.2.8。我正在使用基于重量的运输方法。是否有可能在产品页面中显示的产品实际价格中添加运费?
例如..Product1 =800卢比/-&此产品的运输成本为50卢比/-商店页面中的Product1价格应显示为850卢比/-(实际价格+运输成本)注:运输成本从重量为基础的运输方法计算。这个是可能的吗?
对此有什么想法?
发布于 2017-05-03 20:24:44
发货总是需要一个目的地地址,但当你在商店页面中展示产品时,那里没有可用的地址。但是,由于您可以为每个区域设置统一运费,因此您可以通过自己的方式检索该值并将该价格添加到产品中。如果您需要基于产品的发运价格,请定义发运分类,为产品分配所需的发运分类,并为每个发运分类配置价格。
现在,在前端显示产品价格时,您可以使用以下woocommerce钩子,并将您的逻辑放入修改价格。
function return_custom_price($price, $product) {
//Apply your logic and modify the price
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);发布于 2015-01-27 16:08:54
这是购物车数据
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条件
https://stackoverflow.com/questions/27245789
复制相似问题