【问题标题】:woocommerce initialise shipping method, add to rateswoocommerce 初始化运输方式,添加到费率
【发布时间】:2018-03-05 10:00:42
【问题描述】:

在 Woocommerce 中我有以下情况:100 美元之前有送货方式,100 美元之后只有一个(free shipping) 可用。因此,当客户购买product 102$apply the (10%) promo code 时,价格将为 91,80 美元。因为我在100美元后取消了送货方式,出现after 100$ only包邮,对于客户端显示:“没有shipping methods可用...”

    add_filter( 'woocommerce_package_rates', 'woocommerce_hide_shipping', 10, 2 );
function woocommerce_hide_shipping( $rates, $package ) {

  $threshold = 100;

if ( WC()->cart->subtotal >= $threshold ) {
    unset( $rates['flat_rate:45'] );
    unset( $rates['flat_rate:75'] );
}
if ( WC()->cart->subtotal >= $threshold && !empty(WC()->cart->applied_coupons) ) {
     //code here
}

  return $rates;

}

如果使用促销代码和优惠券之前的price was >100$,是否可以显示免费送货?我设置了免费送货以显示最低订单amount (100$) 但有一种方法可以显示,初始化?也欢迎其他方法。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    问题是....您申请的免费送货受最小订单限制,指的是订单总额(不是小计)..... 而小计为您提供没有折扣的价值。

    所以,

    从您的管理员设置中删除条件(最少订单总数) - 免费送货......现在它适用于每个订单......

    然后修改你的代码---

    add_filter( 'woocommerce_package_rates', 'woocommerce_hide_shipping', 10, 2 );
    function woocommerce_hide_shipping( $rates, $package ) {
    
      $threshold = 100;
    
     if ( WC()->cart->subtotal >= $threshold ) {
        unset( $rates['flat_rate:45'] );
        unset( $rates['flat_rate:75'] );
    }
    if ( WC()->cart->subtotal < $threshold ) {
         //code here
         unset( $rates['free_shipping:45'] );
         unset( $rates['free_shipping:75'] );
    }
    
      return $rates;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-07
      • 2015-01-03
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多