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 Oscar-Abad-Folgueira/62f4a1efebc6b5edc40bfda5703aff81 to your computer and use it in GitHub Desktop.
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
<?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