我有两种配送方式,我想禁用默认的固定费率配送方式。我试过这种方法here 但它不起作用
add_filter( \'woocommerce_package_rates\', \'hide_shipping_method_based_on_shipping_class\', 10, 2 );
function hide_shipping_method_based_on_shipping_class( $rates, $package )
{
if ( is_admin() && ! defined( \'DOING_AJAX\' ) )
return;
// HERE define your shipping class to find
$class = 92;
// HERE define the shipping method to hide
$method_key_id = \'flat_rate:7\';
// Checking in cart items
foreach( $package[\'contents\'] as $item ){
// If we find the shipping class
if( $item[\'data\']->get_shipping_class_id() == $class ){
unset($rates[$method_key_id]); // Remove the targeted method
break; // Stop the loop
}
}
return $rates;
}