Get Company id by company name programmatically in B2B Magento 2.

You can get company id by company name using B2B Magento 2.

You required Company name to fetch company id programmatically using Magento\Company\Api\CompanyRepositoryInterface interface.

Call function from Class or template,

$companyName = “My Company”;
$companyId = $this->getCompanyId($companyName);

Output will be company id based on company name.