WooCommerce:检查订单是否免费送货
WooCommerce: Check if shipping of an order is free
我显示有关免费送货所需数量的信息。
喜欢:
Add 10$ more to get free shipping
一切正常,并且是基于固定金额的免费送货。
我现在的问题是,即使优惠券设置免费送货,它也会显示。
有什么方法可以检查订单是否已经使用任何免费送货方式?
我在这里找到了一些东西:
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') :
我显示有关免费送货所需数量的信息。
喜欢:
Add 10$ more to get free shipping
一切正常,并且是基于固定金额的免费送货。 我现在的问题是,即使优惠券设置免费送货,它也会显示。 有什么方法可以检查订单是否已经使用任何免费送货方式?
我在这里找到了一些东西:
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') :