Snippet Exclude Code not working
-
I am not able to get the Snippet Code to work. I want to run a code to exclude FedEx Ground shipping to all customers living outside of a 2 day delivery area. This is the code I used, that does not work. Any suggestions?
add_filter( ‘woocommerce_package_rates’, ‘wf_remove_shipping_pro_rate_when_free_shipping_is_applicable’, 10, 2 );function wf_remove_shipping_pro_rate_when_free_shipping_is_applicable( $rates, $package )
{$exclude = array(
‘wf_fedex_woocommerce_shipping:FEDEX_GROUND’=>array(‘AK’,’AZ’,’CA’,’CO’,’CT’,’DE’,’FL’,’GA’,’HI’,’ID’,’ME’,’MD’,’MA’,’MT’,’NE’,’NV’,’NH’,’NM’,’ND’,’OK’,’OR’,’RI’,’SD’,’TX’,’UT’,’VT’,’VA’,’WA’,’WY’));
$exclude = array(
‘wf_fedex_woocommerce_shipping:FEDEX_GROUND_HOME_DELIVERY’=>array(‘AK’,’AZ’,’CA’,’CO’,’CT’,’DE’,’FL’,’GA’,’HI’,’ID’,’ME’,’MD’,’MA’,’MT’,’NE’,’NV’,’NH’,’NM’,’ND’,’OK’,’OR’,’RI’,’SD’,’TX’,’UT’,’VT’,’VA’,’WA’,’WY’));if(is_array($exclude)){
foreach($exclude as $shipping_method=>$excluded_states){
if(in_array(WC()->customer->shipping_state, $excluded_states)){
unset($rates[$shipping_method]);}}}return $rates;
}
- The topic ‘Snippet Exclude Code not working’ is closed to new replies.