WooCommerce:检查订单的送货是否免费

显示有关免运费所需金额的信息。


喜欢:


加 10 美元即可免运费


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


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

global $woocommerce;

$shipping_methods = $woocommerce->shipping->load_shipping_methods();

if($shipping_methods['free_shipping']->enabled == "yes")

但这没有帮助。


我还在这里发现了一个有趣的片段: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;

 

}


茅侃侃
浏览 91回答 1
1回答

拉丁的传说

我想我已经解决了:// Loop though shipping packagesforeach ( 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') :
打开App,查看更多内容
随时随地看视频慕课网APP