You stated you copied it over to
app/design/frontend/{my_theme_package}/{my_theme}/page/switch/stores.phtml
which lacks the template folder
The correct path would have been
app/design/frontend/{my_theme_package}/{my_theme}/template/page/switch/stores.phtml
Language switcher shows for multiple languages per website. It does not show if each website has only one language.
In this case, if you want to show switcher, you can show the website switcher.
Please try with the following code:
<?php $websites = $block->getAllWebsites();?>
<div class="switcher store switcher-store" id="switcher-store">
<strong class="label switcher-label"><span><?php echo __('Select Store') ?></span></strong>
<div class="actions dropdown options switcher-options">
<?php foreach ($websites as $website): ?>
<?php if ($websiteid == $website->getId()): ?>
<div class="action toggle switcher-trigger"
role="button"
tabindex="0"
data-mage-init='{"dropdown":{}}'
data-toggle="dropdown"
data-trigger-keypress-button="true"
id="switcher-store-trigger">
<strong>
<span><?php echo $block->escapeHtml($website->getName()) ?></span>
</strong>
</div>
<?php endif; ?>
<?php endforeach; ?>
<ul class="dropdown switcher-dropdown" data-target="dropdown">
<?php foreach ($websites as $website): ?>
<?php if (!($websiteid == $website->getId())): ?>
<li class="switcher-option">
<a href='<?php echo $website->getDefaultStore()->getCurrentUrl() ?>'>
<?php echo $block->escapeHtml($website->getName()) ?>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
Update: As you are using the existing language.phtml file, you also need to create a custom block file and use it in the XML layout file for calling the PHTML file.
The code block file should be like below:
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
) {
$this->_storeManager = $storeManager;
}
public function getWebsites()
{
$_websites = $this->_storeManager->getWebsites();
return $_websites;
}
Now while calling the PHTML file from the layout XML, use the new block class.
Update 2: Location of layout XML file should be under app/design/frontend/{current-theme-package}/{{current-theme}}/Magento_Theme/layout/default.xml
In this file you should see something like:
<block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="Magento_Store::switch/languages.phtml"/>
If yes, you need to change it to:
<block class="Your\Custom\Block\Class" name="store_language" as="store_language" template="Magento_Store::switch/languages.phtml"/>
Best Answer
Website Switcher functionality you can add in header section same as store switcher. I have not created that drop down but I have found one module to automatically switch website using customer current GEO IP address. Please review below link. http://www.logicrays.com/store/magento-2-extensions/multi-website-switcher.html