How to add website switcher in a multi-website environment
How to extend the default Magento Store module
The server environment:
Apache 2.4, Ubuntu 18.04
Multi-website configuration, in this case each website has one store view
Point it out if incorrect: it appears to us that up until 2.3 there is no default website switcher solution in Magento. Due to the limitation of time, we can only demonstrate a quick and dirty way to add your own website switcher.
Please keep it in mind that a website switcher is different from the store switcher, which is usually covered in most third party Magneto themes.
Step 1 – Create Magento Websites and Stores
You can create stores by going to Magento 2 Admin: Stores -> Settings -> All Stores and create your own websites and store views.
One thing in particular we want to point it out is: in our case, we added store code to website URLs. You can configure this by going to Magento 2 Admin: Stores -> Configuration -> General -> Web -> URL Options, and set Add Store Code to URLs to ‘Yes’.
Step 2 – Extend Default Magento Store Template Language.phtml
We found it’s the easiest way to add your own website switcher scripts by extending the default language switcher. Of course, it’s always better to write your own module for such tasks.
In our custom theme, above template file is already included so all we did is modify it in our child theme. Otherwise you can copy:
To many, a business is a lifetime commitment. It's easy to start one yet difficult to make it successful. Attitude, skills, experiences and dedication help hone the craft along the way, but it's often the great vision and resilience to remain focused wins the game. Read more about me here