我有一个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;
}
我在oxygen主题上使用wordpress与woocommerce 2.3.8。
祝你好运
答案 0 :(得分:3)
您使用旧方法,我认为您需要使用此new one。
从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;
}