【问题标题】:WooCommerce: Check if shipping of an order is freeWooCommerce:检查订单是否免费送货
【发布时间】:2020-12-01 14:21:17
【问题描述】:

我显示有关免费送货所需金额的信息。

喜欢:

多加 10 美元即可免运费

这一切都很好,并且是免费送货的固定金额。 我现在的问题是,即使优惠券设置免费送货,它也会显示。 有什么方法可以检查订单是否已经使用任何免费送货方式?

我在这里找到了一些东西:https://stackoverflow.com/a/32932933/1788961

global $woocommerce;
$shipping_methods = $woocommerce->shipping->load_shipping_methods();
if($shipping_methods['free_shipping']->enabled == "yes")

但这并没有帮助。

我还在这里发现了一个有趣的 sn-p:https://www.businessbloomer.com/woocommerce-hide-shipping-options-free-shipping-available/

$all_free_rates = array();
     
foreach ( $rates as $rate_id => $rate ) {
      if ( 'free_shipping' === $rate->method_id ) {
         $all_free_rates[ $rate_id ] = $rate;
         break;
      }
}
     
if ( empty( $all_free_rates )) {
        return $rates;
} else {
        return $all_free_rates;
} 
 
}

【问题讨论】:

    标签: php wordpress woocommerce shipping-method


    【解决方案1】:

    我想我解决了:

    // Loop though shipping packages
    foreach ( WC()->shipping->get_packages() as $key => $package ) {
        // Loop through Shipping rates
        foreach($package['rates'] as $rate_id => $rate ){
            $check_method_shipping = $rate->method_id;
        }
    }
    

    然后你可以像这样使用它:

    if ($check_method_shipping != 'free_shipping') :
    

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 1970-01-01
      • 2014-12-22
      • 2015-08-14
      • 2019-10-13
      • 2014-04-14
      • 2020-11-26
      • 2020-11-05
      相关资源
      最近更新 更多