Created
January 8, 2015 15:49
-
-
Save marcosfreitas/de2f4e9a7930d3514c2a to your computer and use it in GitHub Desktop.
Woocommerce Shipping - Hide standard Shipping Methods when free (local delivery) 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
/* Woocommerce Shipping */ | |
// Hide standard shipping when free is available | |
// Original script https://gist.github.com/pauloiankoski/9707209 | |
add_filter( 'woocommerce_available_shipping_methods', 'mf_hide_standard_shipping_when_free_is_available' , 10, 1 ); | |
function mf_hide_standard_shipping_when_free_is_available( $available_methods ) { | |
global $woocommerce; | |
// First the free shipping method is only available to local delivery | |
// This script works on this way: The local delivery methos identify when the free shipping is available and this identify the | |
// remove free shipping if local delivery is no available | |
/*if ( ! isset( $available_methods['local_delivery'] ) ){ | |
unset( $available_methods['free_shipping'] ); | |
}*/ | |
// Define a fixed minimum value to free local shipping method | |
// if total < 100 R$ the local delivery is available | |
if( $woocommerce->cart->cart_contents_total < 100 AND isset( $available_methods['local_delivery'] ) ) { | |
// remove local delivery | |
unset( $available_methods['local_delivery'] ); | |
// if total >= 100 and local delivery is available | |
} elseif( $woocommerce->cart->cart_contents_total >= 100 AND isset( $available_methods['local_delivery'] ) ) { | |
// remove correios method | |
unset( $available_methods['PAC'] ); | |
unset( $available_methods['SEDEX'] ); | |
} | |
return $available_methods; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment