Select market based on customer address or other profile field (for logged in customers)

With Shopify Markets: Is it possible for Shopify to automatically choose the market for a customer, when the customer logs in, based on the country in the customer’s address? Or based on some other field in the customer’s profile?

In other words, what I would like: When a customer logs in, a market is automatically selected based on something in the customer’s profile. (For example, the country in the customer’s address)

(It looks like Shopify tries to select a market based on geolocation, which has its problems. This is not what I want. I would like the same customer to always go to the same market, when he/she logs in, no matter what his/her geolocation is)

Hi @SomeUsername123 ,

Yes, this can be done with custom coding. You have to edit the registration form to choose country location.

Location should be matched with market place location.

Now write custom code to check the country name which will trigger the market selection.

let me know if you have more questions regarding this.

Hi @gr_trading . Thank you for your reply!

I would love a little more info about how to do this. :slightly_smiling_face: I know JavaScript, but I haven’t done JavaScript in Shopify before, so I would love some pointers. I’ll also just add some questions below, so you can see where some of the holes in my knowledge are :slightly_smiling_face:

Please note that all the customers are created by the admins, in my case, and the registration form is disabled, so there is no need to modify the registration form for my use-case. (So maybe that makes it a bit simpler)

I would love to hear what the overall approach you were thinking of would be - and any hints you could give.
(Is there a JavaScript-event that fires after a user has logged in that could be used? Or would the approach be to check on each page load, whether the current market fits with the currently logged-in customer, and switch to another market if not? Or something else?)

Also, I wonder how you set the market from JavaScript. I haven’t been able to find any documentation on a Shopify JavaScript API (i.e. which objects/methods/functions are available to JavaScript). Do you have a link or some info?
(Or is setting the market from JavaScript done by calling some Webservice-API using AJAX, perhaps, instead of calling JavaScript functions? Or maybe you have to make an URL-path for each market, and redirect to that using JavaScript?)

Ok, sorry for long text - hope you can help :slightly_smiling_face:

P.S. Hmm, I was just thinking: When a market mas multiple countries in it, I wonder how Shopify will behave when you select that market? (Which currency, taxes, etc. does it select and based on what?). Anyway, this is a secondary question :slightly_smiling_face: