Exception or error:
Using the following script in wocommerce Sweden will be removed from both the cart and the checkout
function woo_remove_specific_country( $country )
{
unset($country["SE"]);
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
How can I do see so its only visible in the cart when calculating the shipping price and not visible in the Checkout page?
Kind Regards,
Martin
if ( is_checkout() ) {
function woo_remove_specific_country( $country )
{
unset($country["SE"]);
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
}
Doing following nothing happens when I am in checkout?
Doing following nothines happens as well:
function woo_remove_specific_country( $country ) {
if ( is_checkout() ) {
unset($country["SE"]);
}
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
How to solve:
This is untested as I’ve never worked with woo commerce — it is offered simply as a suggestion… Hopefully this is the hook you can use.
Your add_filter('woocommerce_countres')
will be called every time the countries appear on a page. So you need to be more specific in your targeting.
// Your code to remove the country
function woo_remove_specific_country( $country ) {
if ( is_checkout() ) {
unset($country["SE"]);
}
return $country;
}
// Call the filter function that you already developed... but don't call it every time the countries are shown (see the function call below this function)
function woo_remove_country_filter() {
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
}
// Instead of calling the filter on every page that has "countries", only call it on the checkout form
add_action( 'woocommerce_before_checkout_form', 'woo_remove_country_filter' );