【问题标题】:Woocommerce - Price Dependent Shipping Cost - Is there a better way?Woocommerce - 取决于价格的运费 - 有没有更好的方法?
【发布时间】:2014-10-16 16:28:01
【问题描述】:

我正在寻找一种免费的解决方案(来吧,Wordpress 应该是开源的!)根据购物车价格提供单一的运费选项。比方说,如果购物车总金额为 50 美元及以上,我想免费发货,如果购物车总金额低于要求的金额(即 50 美元),我想收取 4.99 美元。

到目前为止我尝试了什么?

嗯,我能找到的最好的工作解决方案是为所有产品配置统一运费,如果金额大于 X,则免费送货。问题在于这两个选项(免费送货和统一运费) ) 在到达购物车时显示给用户。我不想要那个。

我只想告诉他们,如果他们的购物车金额低于 50 美元,则支付 4.99 美元的运费,以此类推。

到目前为止我尝试过的过滤器: woocommerce_package_rates 不起作用。它甚至没有执行。

我认为为此提供解决方案会很棒,因为我找不到任何解决方案。无论如何,这应该是任何电子商务解决方案的基本特征。

【问题讨论】:

    标签: wordpress woocommerce e-commerce


    【解决方案1】:

    正在寻找这样的插件。

    看起来我为此找到了一个免费插件: https://wordpress.org/plugins/woocommerce-table-rates/stats/

    只安装了它,但还没有测试它,因为我在数据库中没有产品:P

    【讨论】:

      【解决方案2】:

      我正在寻找相同的选项,显然 Woocommerce 本身已经涵盖了它: functions.php 上的所有内容

      WC 3.0+ 的片段

      /**
       * Hide shipping rates when free shipping is available.
       * Updated to support WooCommerce 2.6 Shipping Zones.
       *
       * @param array $rates Array of rates found for the package.
       * @return array
       */
      function my_hide_shipping_when_free_is_available( $rates ) {
          $free = array();
          foreach ( $rates as $rate_id => $rate ) {
              if ( 'free_shipping' === $rate->method_id ) {
                  $free[ $rate_id ] = $rate;
                  break;
              }
          }
          return ! empty( $free ) ? $free : $rates;
      }
      add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
      

      WC 2.5 的片段

      /**
       * woocommerce_package_rates is a 2.1+ hook
       */
      add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
      
      /**
       * Hide shipping rates when free shipping is available
       *
       * @param array $rates Array of rates found for the package
       * @param array $package The package array/object being shipped
       * @return array of modified rates
       */
      function hide_shipping_when_free_is_available( $rates, $package ) {
      
          // Only modify rates if free_shipping is present
          if ( isset( $rates['free_shipping'] ) ) {
      
              // To unset a single rate/method, do the following. This example unsets flat_rate shipping
              unset( $rates['flat_rate'] );
      
              // To unset all methods except for free_shipping, do the following
              $free_shipping          = $rates['free_shipping'];
              $rates                  = array();
              $rates['free_shipping'] = $free_shipping;
          }
      
          return $rates;
      }
      

      来源:https://docs.woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/

      我已经测试并且工作正常,Woocommerce 缓存擦除很重要,否则会一直显示所有选项。

      【讨论】:

        【解决方案3】:

        Woocommerce 具有内置的“免费送货”运输方式,可以选择指定最低金额。应该正是你的情况。

        【讨论】:

        • 我不想有多种选择,例如.. 统一运费和免费送货.. 我只想有一个选项,如果金额大于 x 则免费送货,或者如果金额大于 x 则统一运费数量小于 x。
        • 好吧,你已经成功了。如果您确实需要隐藏购买超过所需金额的其他选项,您正在寻找的过滤器是woocommerce_available_payment_gateways。
        • 抱歉,弄混了。过滤器处理运输似乎是woocommerce_cart_shipping_packages。这部分似乎比以前的版本更令人困惑。
        • 或者更确切地说,直接从多余的方法修改可用性:apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package ); - 过滤器将是 `woocommerce_shipping_free_shipping_is_avaible'。
        猜你喜欢
        • 2022-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-04
        • 1970-01-01
        • 2019-07-29
        • 1970-01-01
        • 2021-08-24
        相关资源
        最近更新 更多