我显示免费送货所需金额的信息。
类似:
再加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;
}
}
我想我解决了它:
// 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') :