【发布时间】:2016-10-16 07:18:49
【问题描述】:
我最近在我的商店更新到 WooCommerce 2.6,他们更新了他们的运输系统。在达到特定订单价值并触发免费送货时,我使用它来隐藏付费送货选项:
/**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
* @return array of modified rates
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
// Only modify rates if free_shipping is present
if ( isset( $rates['free_shipping'] ) ) {
// To unset a single rate/method, do the following. This example unsets flat_rate shipping
unset( $rates['flat_rate'] );
// To unset all methods except for free_shipping, do the following
$free_shipping = $rates['free_shipping'];
$rates = array();
$rates['free_shipping'] = $free_shipping;
}
return $rates;
}
虽然这不再起作用了。我需要一个新的修复程序,而我并不真正喜欢编码。
有没有人可以解决这个问题?
以上解决方案来自这个网站:
Hide other shipping methods when FREE SHIPPING is available
我猜有些参数在更新运输方式后发生了变化。
我希望有人知道如何解决这个问题。
【问题讨论】:
标签: php wordpress woocommerce shipping