You can use getCount() method to retrieve total number of website available in the system using Magento 2.
You can manually count all the website list from the Admin panel via Stores -> Setting -> All stores.
Interface Provides the functionality:
Magento\Store\Api\WebsiteManagementInterface
By Programmatically You can use the below code snippet to total website,
<?php namespace Jesadiya\WebsiteCount\Model; use Magento\Store\Api\WebsiteManagementInterface; class WebsiteCount { /** * @var WebsiteManagementInterface */ private $websiteManagement; public function __construct( WebsiteManagementInterface $websiteManagement ) { $this->websiteManagement = $websiteManagement; } /** * Get Website Count of the system * * @return int */ public function getWebsiteCount(): int { $websiteCount = $this->websiteManagement->getCount(); return $websiteCount; } }
Call from the template or any PHP class,
echo $websiteCount = $this->getWebsiteCount();
Output: 2
Return the result of available website in a system.