当免费送货可用时隐藏所有其他运送方式
https:// Hide ALL shipping options when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 );
/**
* Hide ALL Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_all_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) :
https:// Get Free Shipping array into a new array
$freeshipping = array();
$freeshipping = $available_methods['free_shipping'];
https:// Empty the $available_methods array
unset( $available_methods );
https:// Add Free Shipping back into $avaialble_methods
$available_methods = array();
$available_methods[] = $freeshipping;
endif;
return $available_methods;
}
在哪里添加此代码?
将PHP代码放在主题或子主题functions.php文件的底部。
请问是加在哪个文件里?
放在主题或子主题 functions.php文件底部