How to Add Timezone & Locale Dropdown in Custom Form in Frontend in Magento 2

How to Add Timezone & Locale Dropdown in Custom Form in Frontend in Magento 2

Magento 2 CMS is widely used global platform for online stores. Magento 2 stores serve customers from various location living in different time zones.

If you are a business that offers on-call support, you may require to know the time zone of your customer’s location. Or if you have implemented shipping restrictions based on locale, you may require to know the locale information of your customer before accepting their orders.

In such scenarios, you may add timezone & locale dropdown in custom form in frontend in Magento 2 as shown below:

The timezone and locale in a custom form

Timezone

Locale

Use the below code to get the customers’ time zone and locale data from the frontend as shown in the above figure.

Steps to Add Timezone & Locale Dropdown in Custom Form in Frontend in Magento 2

  1. Add the below code in your block file.
  2. Add the below code in your phtml file.

That’s it!

If you have any doubts about the solution, mention them in the Comments section below.

I would be happy to help.

Feel free to share the solution with Magento Community via social media.

Thank You.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 11 Reviews)

He has been with Meetanshi for more than two years now as a Magento developer. A silent guy whom you can always find solving clients' issues, is an avid reader too.

Leave a reply:

Your email address will not be published.