Created
October 3, 2017 15:22
-
-
Save Nishadup/8f0614fccabb52842eb5b4a5051057e3 to your computer and use it in GitHub Desktop.
Hide shipping methods if freeshipping/flatrate exists.
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
add_filter('woocommerce_package_rates', 'xa_hide_shipping_methods_if_free_flaterate_exist', 10, 2); | |
if(!function_exists('xa_hide_shipping_methods_if_free_flaterate_exist')){ | |
function xa_hide_shipping_methods_if_free_flaterate_exist( $available_shipping_methods, $package ){ | |
$hide_if_shpping_method_exist = array('free_shipping','flat_rate'); //If the shipping methods given here is exists. | |
$method_to_hide = array('wf_australia_post'); //Hide all the shipping method provided here. | |
$do_hide = false; | |
foreach ($hide_if_shpping_method_exist as $method) { | |
foreach ($available_shipping_methods as $shipping_method => $value) { | |
if( strpos( $shipping_method, $method ) !== false ) { | |
$do_hide=true; | |
break 2; | |
} | |
} | |
} | |
if( $do_hide ){ | |
foreach ($method_to_hide as $method) { | |
xa_hide_the_shipping_method( $method, $available_shipping_methods ); | |
} | |
} | |
return $available_shipping_methods; | |
} | |
} | |
if(!function_exists('xa_hide_the_shipping_method')){ | |
function xa_hide_the_shipping_method($method, &$available_shipping_methods){ | |
foreach ($available_shipping_methods as $shipping_method => $value) { | |
if( strpos( $shipping_method, $method ) !== false ) { | |
unset($available_shipping_methods[$shipping_method]); | |
} | |
} | |
return $available_shipping_methods; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment