【问题标题】:how to add shipping cost with product actual price?如何将运费与产品实际价格相加?
【发布时间】:2015-01-30 11:38:52
【问题描述】:

我正在为我的电子商务网站使用 woocommerce 插件 v2.2.8。我正在使用基于重量的运输方式。是否有可能在产品页面显示的产品实际价格中添加运费?

例如.. Product1 = 800 卢比/- 并且该产品的运费为 50 卢比/- 商店页面中的 Product1 价格应显示为 850 卢比/-(实际价格 + 运费)注意:运费根据重量计算。这可能吗?

关于这个有什么想法吗???

【问题讨论】:

    标签: wordpress woocommerce shipping


    【解决方案1】:

    运送总是需要一个目的地地址,但是当您在商店页面中展示产品时,那里没有可用的地址。但是,由于您可以为每个区域设置统一运费设置,因此您可以自行检索该值并将该价格添加到产品中。如果您需要基于产品的运费,请定义运费等级,将所需的运费等级分配给产品并为每个运费等级配置价格。

    现在在前端显示产品价格时,您可以使用以下 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);
    

    【讨论】:

      【解决方案2】:

      这是您的购物车数据

      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>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$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 条件

      【讨论】:

      • 您能否在代码中添加更多解释和格式。事实上,人们可能不会觉得这个答案很有用。
      • 问题是关于在 SHOP 页面中显示包括运费在内的价格。这根本不是答案。
      猜你喜欢
      • 2019-04-18
      • 1970-01-01
      • 2021-08-03
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2018-09-02
      相关资源
      最近更新 更多