我有一个wordpress/woocommerce站点。当用户购物车金额超过500时,我必须在购物车小计中免费送货。现在,我已经设置了统一费率25和免费送货,如果金额超过500。
我谷歌它从帮助和添加一些代码到functions.php,但仍然有同样的问题。
function hide_all_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) :
// Get Free Shipping array into a new array
$freeshipping = array();
$freeshipping = $available_methods['free_shipping'];
// Empty the $available_methods array
unset( $available_methods );
// Add Free Shipping back into $avaialble_methods
$available_methods = array();
$available_methods['free_shipping'] = $freeshipping;
endif;
return $available_methods;
}
我使用wordpress与woocommerce 2.3.8的氧主题。
你用的是老方法,我觉得你需要用这个新方法。
复制自WooThemes网站:
add_filter( 'woocommerce_package_rates','hide_shipping_when_free_is_available', 10, 2 );
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;
}