【问题标题】:Shipping options depending on cart weight运输选项取决于购物车重量
【发布时间】:2019-12-28 03:32:53
【问题描述】:

我正在开发一个使用 Woocommerce 的 Wordpress 网站。 我发现这段代码允许根据重量设置货运选项,但我需要有价格: - 从 0 到 2 公斤 = 10 欧元 - 然后 2 公斤到 5 公斤 = 15 欧元 - 然后 5 公斤到 10 公斤 = 20 欧元 依此类推,直到 20 公斤。 超过 20 公斤,仅按需提供。 这是我尝试使用和修改的代码:

add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 9999, 2 );

function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {

     if ( WC()->cart->get_cart_contents_weight() < 2 ) {

         if ( isset( $rates['flat_rate:32'] ) ) unset( $rates['flat_rate:32'], $rates['flat_rate:32'] );

     } elseif ( WC()->cart->get_cart_contents_weight() < 5 ) {

         if ( isset( $rates['flat_rate:32'] ) ) unset( $rates['flat_rate:32'], $rates['flat_rate:33'] );

     } elseif ( WC()->cart->get_cart_contents_weight() < 10 ) {

         if ( isset( $rates['flat_rate:32'] ) ) unset( $rates['flat_rate:32'], $rates['flat_rate:34'] );

     } elseif ( WC()->cart->get_cart_contents_weight() < 15 ) {

         if ( isset( $rates['flat_rate:32'] ) ) unset( $rates['flat_rate:32'], $rates['flat_rate:35'] );

      } elseif ( WC()->cart->get_cart_contents_weight() < 20 ) {

         if ( isset( $rates['flat_rate:32'] ) ) unset( $rates['flat_rate:32'], $rates['flat_rate:36'] );

     }

     return $rates;

}

谢谢, 大卫

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    我确实找到了一段更适合价格的代码。 现在我只有 20 公斤以上的问题......如何通知“按需”而不是价格? 最好的, 大卫

    【讨论】:

      猜你喜欢
      • 2019-01-01
      • 2013-03-22
      • 2014-05-05
      • 2021-05-30
      • 2017-07-07
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多