Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeroenSormani/27a0b0d584af7152040196fdc3582212 to your computer and use it in GitHub Desktop.
Save JeroenSormani/27a0b0d584af7152040196fdc3582212 to your computer and use it in GitHub Desktop.
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