mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
https://stackoverflow.com/questions/76990069/woocommerce-hide-local-pickup-shipping-option-if-order-total-is-zero
13 lines
488 B
Text
13 lines
488 B
Text
add_filter( 'woocommerce_package_rates', 'hide_local_pickup_for_free_orders', 10, 2 );
|
|
function hide_local_pickup_for_free_orders( $rates, $package ) {
|
|
// If cart subtotal is equal to zero
|
|
if( $package['contents_cost'] == 0 ) {
|
|
foreach( $rates as $rate_key => $rate ) {
|
|
// Hide Local Pickup shipping method(s)
|
|
if ( $rate->method_id === 'local_pickup' ) {
|
|
unset($rates[$rate_key]);
|
|
}
|
|
}
|
|
}
|
|
return $rates;
|
|
}
|