以下是一些GIST从GitHub问题讨论中收集的片段,另一个答案中由@Ewout链接。我添加了一个var_dump()
, 因此,您可以取消注释并检查要删除的内容。
$available_methods
是一个array
其中:
$available_methods as $method_id => $method
对比
$method_id
如果您需要更具体的检查。
// Hide standard shipping option when free shipping is available
add_filter( \'woocommerce_available_shipping_methods\', \'wpse90835_hide_standard_shipping_when_free_is_available\' );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function wpse90835_hide_standard_shipping_when_free_is_available( $available_methods )
{
// Developers!: Dump this to see what you can unset
# var_dump( $available_methods );
// remove standard shipping option
if (
isset( $available_methods[\'free_shipping\'] )
AND isset( $available_methods[\'flat_rate\'] )
)
unset( $available_methods[\'flat_rate\'] );
return $available_methods;
}