Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide other rates when Advanced Shipping is available.
<?php
/**
* Copy from here to your (child) themes functions.php
* Recommended to do so via FTP.
*/
/**
* Only show Advanced Shipping rates when available.
*
* Hides all non-Advanced Shipping rates..
*/
function custom_hide_other_rates_when_advanced_shipping_is_available( $shipping_rates) {
$was_rates = array();
foreach ( $shipping_rates as $key => $rate ) {
// Check for Advanced Shipping rates
if ( $rate->method_id == 'advanced_shipping' ) {
$was_rates[ $key ] = $rate;
}
}
// Show all/only Advanced Shipping rates
if ( ! empty( $was_rates) ) {
return $was_rates;
}
return $shipping_rates;
}
add_filter( 'woocommerce_package_rates', 'custom_hide_other_rates_when_advanced_shipping_is_available' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment