Created
March 30, 2017 17:11
-
-
Save JeroenSormani/27a0b0d584af7152040196fdc3582212 to your computer and use it in GitHub Desktop.
Hide other rates when Advanced Shipping is available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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