Get Current Website code programmatically magento 2.

We can get Current website code programmatically using Magento 2 by StoreManagerInterface.

By default, Single website have default assigned code is “default”

If you are working with multiple website eCommerce stores, You need to fetch current website code for respected website programmatically on some occasion.

You can fetch current website code by below code snippet,

Call function,
echo $this->getWebsiteCode();

Output:
Returns Current Website code.