What the best way to change text add to cart only for not registered users?

  1. Documentation recommend change dictionary file. https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/translations/translate_practice.html but this solution works for all users
  2. Create some plugin/observer for Magento\Framework\Phrase\Renderer\Translate.

There are many ways to achieve this, but I would recommend it by overriding the template file.

To do so, just copy the file /vendor/magento/module-catalog/view/frontend/templates/product/list.phtml and put it under app/design/frontend/{theme-package}/{theme}/Magento/Catalog/templates/product folder.

Now you can programmatically check whether a customer is logged into the website or not, and based on that you can change the value of __('Add to Cart') to whatever you want.

Since the solution needs some custom code, it is not possible by simply writing the translation in the translation files.

The above solution is the simplest one and it also does not break any Magento standard.

  • this might not work with FPC enabled – igrossiter Feb 2 '19 at 12:50

You have to override js file from path and all user for translate text this file




You have to changes text which you want to from this file.


I think the simple solution to change the "Add to cart" only for not registred users is to do something like this:

Not registred means not logged in


/** @var $block \Magento\Catalog\Block\Product\View */
<?php $_product = $block->getProduct(); ?>

/* ***** We do our stuff right here ***** */
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
    $buttonTitle = __('Add to Cart');
} else {
    $buttonTitle = __('Text for not registred user');


In the case you want to get the registred users:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$website_id = $storeManager->getStore()->getWebsiteId();
$customer = $objectManager->get('Magento\Customer\Model\Customer');

if ( $customer->getId() ) {
      // the customer exist
} else {
      // does't exist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.