Hiding countries you don’t want to see in the plugin admin settings
-
I am developing a site with this plugin and my customer doesn’t ship worldwide – only to the US and Canada.
I added some code to the includes/class-wc-advanced-shipment-tracking-admin.php file in the woocommerce_advanced_shipment_tracking_page_callback function just before the $default_shipment_providers database query on line 668 of version 2.0.7. This code limits the providers returned in the list to only the countries specified in the default WooCommerce settings under the General options.
The code is also configured to detect if the user selects differing countries for selling to and shipping to so it should be pretty universal.
I’d like to ask @zorem to consider adding this as a permanent feature since there is no other way to remove unused shipping providers or hide them from the admin settings page view right now.
It’s not fully tested but it does work for my purposes. Hope this helps someone else if they are looking for the same solution.
The code:
/** BEGIN limit to countries set in WooCommerce settings for countries that this seller sells to or specifies for shipping to **/ $limit_countries = false; $shipping_countries = null; $country_limitations = ''; $woocommerce_ship_to_countries = get_option( 'woocommerce_ship_to_countries' ); if (empty($woocommerce_ship_to_countries)) { $limit_countries = true; $shipping_countries = get_option( 'woocommerce_specific_allowed_countries' ); } if ($woocommerce_ship_to_countries==="specific") { $limit_countries = true; $shipping_countries = get_option( 'woocommerce_specific_ship_to_countries' ); } if ($limit_countries === true) { if (is_array($shipping_countries)) { $woo_shipping_zones_count = count($shipping_countries); if ($woo_shipping_zones_count>0) { $country_limitations = " WHERE ("; $cl_count = 1; foreach ($shipping_countries as $key=>$country_code){ $country_limitations .= "shipping_country='".$country_code."'"; if ($cl_count < $woo_shipping_zones_count) { $country_limitations .= " OR "; } $cl_count++; } $country_limitations .= ")"; $woo_shippment_table_name .= $country_limitations; } } } /** END limitations **/
- The topic ‘Hiding countries you don’t want to see in the plugin admin settings’ is closed to new replies.