Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to limit the WooCommerce checkout form to specific countries for each language?

Solution:

This is part of the solution for the issues that were presented in this thread.

You can try and use this custom code in the functions.php file of your theme.

function woo_override_checkout_fields_billing( $fields ) { 
    if(ICL_LANGUAGE_CODE=='tr'){
    $fields['billing']['billing_country'] = array(
        'type'      => 'select',
        'label'     => __('My New Country List', 'woocommerce'),
        'options'   => array('TR' => 'Turkey')
    );
    }
    elseif (ICL_LANGUAGE_CODE=='en'){
        $fields['billing']['billing_country'] = array(
            'type'      => 'select',
            'label'     => __('My New Country List', 'woocommerce'),
            'options'   => array('AU' => 'Australia')
        ); 
    }
    return $fields;
} 
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields_billing' );

Of cours, that this is an example and you will need to do some adjatments for this code to your case/countries.

Relevant Documentation:

This code is based on the information from the following links.

https://stackoverflow.com/questions/45385808/strict-to-1-country-only-in-checkout-page-with-wordpress-and-woocommerce

https://wpml.org/documentation/support/wpml-coding-api/

It is important to mention that since it is custom code and it involves a third party function (WooCommerce), we will not be able to support it or guarantee that it will work.

100% of people find this useful.

This topic contains 15 replies, has 2 voices.

Last updated by Itamar 2 years ago.

Assigned support staff: Itamar.

Author Posts
October 24, 2017 at 6:44 pm #1410504

kamalpreetS

Hi there,

How can I limit countries during checkout as some people are automatically using US prices to turn Canadian and pay without conversion. How do I fix this?

For example, someone visits: hidden link

They fill out the form and go all the way to check out. Once they go to checkout and change their country to Canada, they still pay the same price without conversion. How is this even possible? That's the reason why I have WPML and WooCommerce.

October 25, 2017 at 8:50 am #1410997

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hello.

I've visited the link that you shared with me and filled the form, and I could see that the price does not change.
You write: "Once they go to checkout and change their country to Canada..."
So from what I see a user needs to type the country and not select or change it from a list like it is usually in the checkout process with WooCommerce.
Please see attached screenshot convert-currency.jpg
Is correct or am I missing something?
If so then it looks to me that the form that you are using is not integrated with WooCommerce.
Let's, for example, say that you want to add tax to this product does it then added to the price (24.99$)?
Can you give me more details about this form and you have created it?

Regards,
Itamar.

October 25, 2017 at 12:24 pm #1411276

kamalpreetS

Hi @itamar,

Sorry I think you didn't understand. The entire form is here: hidden link

Once you fill out the entire form (if you can do so with any test fields, etc.), you'll see it redirect to WooCommerce Cart/Checkout. When checking out, the listed countries available include Canada although being on the USA website: hidden link

When you select Canada, the currency doesn't convert. I want people to have a converted currency even if they choose Canada because I don't want my Canadian clients ordering from the US website. Right now it's not even converting and that's all through WPML. Please advise.

October 25, 2017 at 5:41 pm #1411863

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

Because it wasn't clear to me from which form I should start, I have gone through the checkout process twice. First starting from here hidden link and the second time starting from here hidden link
On both cases the currency at the checkout page was CAD.
Please see attached screenshots ca-checkout.jpg and us-checkout.jpg
So for me it looks like checking out on the Canadian site works OK and the problem is that when checking out on the US site the currency is CAD and USD.
Do I understand the problem now correctly?

October 26, 2017 at 3:15 pm #1413129

kamalpreetS

Hi @itamar,

For the USA, it just states CAD but it's not really CAD for the US website. If you go to PayPal it'll show you in USD.

The issue is if you choose "Canada" in the country under the USA checkout, the currency doesn't convert. People are able to pay in CAD which shouldn't be allowed!

October 29, 2017 at 3:51 pm #1415042

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi and sorry for the late response here.

OK, now I can see the problem on your site.
If I check out from the US site and select in my billing details 'Canada' and then proceed to pay with PayPal, I get the currency in USD and not in CAD. Please see attached screenshot paypal-issue.jpg. Is this correct?

Could you, please tell me what are the multi-currency settings (WooCommerce -> WooCommerce Multilingual -> Multi-currency tab) that you have set?
Please see attached screenshot multi-currency-settings.jpg
A screenshot of your settings could be helpful as well.

Thanks,
Itamar.

October 30, 2017 at 2:53 pm #1415815

kamalpreetS

Hi Itamar,

Here are the issues clearly, similar to how you defined the issue:

1. You are correct, on the US website when checking out and selecting Canada, it doesn't convert the USD to CAD. Also, tax doesn't show up. This happens vice versa.

2. What people are doing to take advantage of the flaw, is for the Canadian website, people are putting USA in the billing country which ends up avoiding tax for people when checking out. This shouldn't be allowed.

Next step is:

1. Currency should convert automatically so people can't avoid paying the difference.

2. How can we limit the countries on checkout for each version of the site? We should remove Canada from the USA and remove USA from Canada.

Attached are the settings on the WooCommerce Multilingual page.

October 31, 2017 at 12:09 pm #1416727

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

You write: "1. Currency should convert automatically so people can't avoid paying the difference."
When using WooCommerce Multilingual and its multicurrency option and once you are already on the checkout page the currency will not change according to the country that you select on the checkout page. The currency of the product will be the currency that the users will select (if the currency switcher is enabled) before they get to the checkout page. And changing the country on the checkout page will never change the currency for the product at this stage.
The only suggestion for you that I can think of to what you want to achieve is setting the multi-currency options in a way that will only show USD for USA and CAD for Canada. Please see attached screenshot (the French flag represents Canada, for example). This way when users of your site will use the Canadian version of your site (hidden link) they will only be able to see the prices of the products in CAD and on the checkout they will only be able to pay in CAD. And when users of your site will use the USA version (hidden link) they will only be able to see and pay in USD.

You ask: "How can we limit the countries on checkout for each version of the site? We should remove Canada from the USA and remove USA from Canada."
In WooCommerce -> Settings -> General you can choose 'Sell to specific countries' and the countries that you choose will show in each language of your site. Currently, there is no option with WooCommerce Multilingual to show specific countries for a specific language (USA or Canada in your case). We have an add-on that does something similar to what you want to achieve but with selecting payment gateways per country and that is not what you need.
It seems that for now, you need custom programming work which is beyond the scope of our support. At this point I would suggest you consider contacting one of our certified partners from this link:
http://wpml.org/documentation/support/wpml-contractors/
Before doing so, please have a look also here:
http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/
You will get the custom assistance you need to get on with your project.

Please let me know if my answers address your issue.

Regards,
Itamar.

November 8, 2017 at 9:59 pm #1425196

kamalpreetS

Hi there,

See attached my screenshot. What happens is that someone selects USA from the Canadian website to get no tax in checkout and they'll still pay Canadian given the site is the Canadian version thus CAD. How can we stop that?

November 9, 2017 at 8:13 pm #1426528

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

I may be failing to understand what you want to achieve, so I'm consulting our second tier supporter about this issue.
I'll get back to you here when I have his reply on this.

November 13, 2017 at 3:27 pm #1429100

kamalpreetS

Hi Itamar,

Any word on this?

Thanks,

Baljot

November 13, 2017 at 4:00 pm #1429130

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, Baljot.

Our second tier confirms what I have said here and says that WPML does not control the WooCommerce country based on the language of the site. Languages can be limited, but countries can be all.
We suggest you use what WooCommerce has to offer to achieve what you need.
Probably this can be done charging extra tax if the user entered Canda shipping address.
More information about this option can be found at the following link to WooCommerce documentation.
https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce/
You can change the tax according to the country that the user is selecting and thus make the user pay the needed price.

Or restrict shipping countries list on Woocommerce checkout page by adjusting the code example that is attached to the article in the following link.
hidden link
The code then will look like this.

function woo_override_checkout_fields( $fields ) { 
	if (apply_filters( 'wpml_current_language', 'us')) {	
		$fields['shipping']['shipping_country'] = array(
			'type'      => 'select',
			'label'     => __('My New Country List', 'woocommerce'),
			'options' 	=> array('US' => 'United States')
		);
	}
	elseif (apply_filters( 'wpml_current_language', 'ca' )) {
		$fields['shipping']['shipping_country'] = array(
			'type'      => 'select',
			'label'     => __('My New Country List', 'woocommerce'),
			'options' 	=> array('CA' => 'Canada')
		);	
	}
 
	return $fields; 
} 
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields' );

Please note that the above code was not tested and is just a suggestion.
You should try and see if it works correctly.

Regards,
Itamar.

November 13, 2017 at 4:04 pm #1429134

kamalpreetS

Hi Itamar,

Thank you for the response. I think the code you provided is the right direction. One adjustment I have and with your guidance it would be perfect.

Can you provide a code that would restrict Canada from the USA website and restrict USA from the Canada website? Because people on the USA website should be allowed to order from any country excluding Canada. For Canada, it's only Canada and no other country in the world..

Thank you!!

November 13, 2017 at 4:15 pm #1429168

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

I see, Baljot.

So for Canada, I believe that the second part of the suggested code will get you what you need.
And I'm sorry, but for the other adjustment that you need, you would need to get support from WooCommerce as it is out of the scope of this forum.

Thank you for your understanding.

Best regards,
Itamar.

November 17, 2017 at 3:22 pm #1434089

kamalpreetS

Hi Itamar,

Unfortunately the code you provided didn't work. Can you try testing on my website here: hidden link

All countries are still available when checking out for some reason.

Baljot