Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Snippet to hide WooCommerce shipping methods on the cart/checkout page based on the destination country. Supports PluginHive Shipping Plugins:
add_filter('woocommerce_package_rates', 'wf_remove_shipping_options_for_particular_country', 10, 2);
function wf_remove_shipping_options_for_particular_country($available_shipping_methods, $package){
global $woocommerce;
//Config this array with country code and corresponding shipping methods to hide.
$country_list = array(
'CA' => array('wf_fedex_woocommerce_shipping','free_shipping'),
$customer_country = $woocommerce->customer->get_shipping_country();
if ( in_array( $customer_country , array_keys($country_list) ) ) {
if( !empty( $country_list[$customer_country] ) ){
foreach ($country_list[$customer_country] as $shipping_methods) {
foreach ($available_shipping_methods as $shipping_method => $value) {
if( strpos( $shipping_method, $shipping_methods ) !== false ) {
return $available_shipping_methods;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.