顯示有關免運費所需金額的信息。喜歡:加 10 美元即可免運費一切正常,并且基于固定金額的免費送貨。我現在的問題是,即使優惠券設置免費送貨,它也會顯示。有什么方法可以檢查訂單是否已經使用任何免費送貨方式?我在這里找到了一些東西:https ://stackoverflow.com/a/32932933/1788961global $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;} }
1 回答

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
我想我已經解決了:
// 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') :
- 1 回答
- 0 關注
- 112 瀏覽
添加回答
舉報
0/150
提交
取消