Created
May 28, 2020 13:57
-
-
Save Oscar-Abad-Folgueira/62f4a1efebc6b5edc40bfda5703aff81 to your computer and use it in GitHub Desktop.
WooCoomerce Snippet - Ocultar métodos de envío si existe método de envío gratis
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 | |
/** | |
* @snippet WooCoomerce Snippet - Ocultar métodos de envío si existe método de envío gratis. | |
* @author Oscar Abad Folgueira | |
* @author_url https://www.oscarabadfolgueira.com | |
* @snippet_url https://www.oscarabadfolgueira.com/ocultar-metodos-de-envio-si-existe-envio-gratis-en-woocommerce | |
*/ | |
add_filter( 'woocommerce_package_rates', 'oaf_unset_shipping_when_free_is_available_all_zones', 10, 2 ); | |
function oaf_unset_shipping_when_free_is_available_all_zones( $rates, $package ) { | |
$all_free_rates = array(); | |
foreach ( $rates as $rate_id => $rate ) { | |
if ( 'free_shipping' === $rate->method_id ) { | |
$all_free_rates[ $rate_id ] = $rate; | |
break; | |
} | |
} | |
if ( empty( $all_free_rates )) { | |
return $rates; | |
} else { | |
return $all_free_rates; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment