Change “add to cart” text for not registered users












4















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 MagentoFrameworkPhraseRendererTranslate.










share|improve this question





























    4















    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 MagentoFrameworkPhraseRendererTranslate.










    share|improve this question



























      4












      4








      4


      3






      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 MagentoFrameworkPhraseRendererTranslate.










      share|improve this question
















      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 MagentoFrameworkPhraseRendererTranslate.







      magento2 addtocart






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 25 at 10:10









      PЯINCƏ

      8,21831143




      8,21831143










      asked Jan 25 at 9:39









      Max OMax O

      415




      415






















          3 Answers
          3






          active

          oldest

          votes


















          1














          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.






          share|improve this answer
























          • this might not work with FPC enabled

            – igrossiter
            Feb 2 at 12:50



















          1














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



          vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js  


          To



          app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-cart.js


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






          share|improve this answer

































            0














            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




            app/design/frontend/{Vendor}{themename}/Magento_Catalog/templates/product/view/addtocart.phtml




            /** @var $block MagentoCatalogBlockProductView */
            ?>
            <?php $_product = $block->getProduct(); ?>

            /* ***** We do our stuff right here ***** */
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $customerSession = $objectManager->get('MagentoCustomerModelSession');
            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 = MagentoFrameworkAppObjectManager::getInstance();
            $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
            $website_id = $storeManager->getStore()->getWebsiteId();
            $customer = $objectManager->get('MagentoCustomerModelCustomer');
            $customer->setWebsiteId($website_id);
            $customer->load('CUSTOMER_ID');

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





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "479"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f259227%2fchange-add-to-cart-text-for-not-registered-users%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              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.






              share|improve this answer
























              • this might not work with FPC enabled

                – igrossiter
                Feb 2 at 12:50
















              1














              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.






              share|improve this answer
























              • this might not work with FPC enabled

                – igrossiter
                Feb 2 at 12:50














              1












              1








              1







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 25 at 10:00









              Mohit Kumar AroraMohit Kumar Arora

              6,64141632




              6,64141632













              • this might not work with FPC enabled

                – igrossiter
                Feb 2 at 12:50



















              • this might not work with FPC enabled

                – igrossiter
                Feb 2 at 12:50

















              this might not work with FPC enabled

              – igrossiter
              Feb 2 at 12:50





              this might not work with FPC enabled

              – igrossiter
              Feb 2 at 12:50













              1














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



              vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js  


              To



              app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-cart.js


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






              share|improve this answer






























                1














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



                vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js  


                To



                app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-cart.js


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






                share|improve this answer




























                  1












                  1








                  1







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



                  vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js  


                  To



                  app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-cart.js


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






                  share|improve this answer















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



                  vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js  


                  To



                  app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-cart.js


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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 23 at 4:39









                  Teja Bhagavan Kollepara

                  2,98641947




                  2,98641947










                  answered Jan 25 at 9:42









                  Rakesh DongaRakesh Donga

                  1,599316




                  1,599316























                      0














                      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




                      app/design/frontend/{Vendor}{themename}/Magento_Catalog/templates/product/view/addtocart.phtml




                      /** @var $block MagentoCatalogBlockProductView */
                      ?>
                      <?php $_product = $block->getProduct(); ?>

                      /* ***** We do our stuff right here ***** */
                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $customerSession = $objectManager->get('MagentoCustomerModelSession');
                      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 = MagentoFrameworkAppObjectManager::getInstance();
                      $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
                      $website_id = $storeManager->getStore()->getWebsiteId();
                      $customer = $objectManager->get('MagentoCustomerModelCustomer');
                      $customer->setWebsiteId($website_id);
                      $customer->load('CUSTOMER_ID');

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





                      share|improve this answer




























                        0














                        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




                        app/design/frontend/{Vendor}{themename}/Magento_Catalog/templates/product/view/addtocart.phtml




                        /** @var $block MagentoCatalogBlockProductView */
                        ?>
                        <?php $_product = $block->getProduct(); ?>

                        /* ***** We do our stuff right here ***** */
                        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                        $customerSession = $objectManager->get('MagentoCustomerModelSession');
                        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 = MagentoFrameworkAppObjectManager::getInstance();
                        $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
                        $website_id = $storeManager->getStore()->getWebsiteId();
                        $customer = $objectManager->get('MagentoCustomerModelCustomer');
                        $customer->setWebsiteId($website_id);
                        $customer->load('CUSTOMER_ID');

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





                        share|improve this answer


























                          0












                          0








                          0







                          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




                          app/design/frontend/{Vendor}{themename}/Magento_Catalog/templates/product/view/addtocart.phtml




                          /** @var $block MagentoCatalogBlockProductView */
                          ?>
                          <?php $_product = $block->getProduct(); ?>

                          /* ***** We do our stuff right here ***** */
                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $customerSession = $objectManager->get('MagentoCustomerModelSession');
                          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 = MagentoFrameworkAppObjectManager::getInstance();
                          $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
                          $website_id = $storeManager->getStore()->getWebsiteId();
                          $customer = $objectManager->get('MagentoCustomerModelCustomer');
                          $customer->setWebsiteId($website_id);
                          $customer->load('CUSTOMER_ID');

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





                          share|improve this answer













                          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




                          app/design/frontend/{Vendor}{themename}/Magento_Catalog/templates/product/view/addtocart.phtml




                          /** @var $block MagentoCatalogBlockProductView */
                          ?>
                          <?php $_product = $block->getProduct(); ?>

                          /* ***** We do our stuff right here ***** */
                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $customerSession = $objectManager->get('MagentoCustomerModelSession');
                          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 = MagentoFrameworkAppObjectManager::getInstance();
                          $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
                          $website_id = $storeManager->getStore()->getWebsiteId();
                          $customer = $objectManager->get('MagentoCustomerModelCustomer');
                          $customer->setWebsiteId($website_id);
                          $customer->load('CUSTOMER_ID');

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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 25 at 10:05









                          PЯINCƏPЯINCƏ

                          8,21831143




                          8,21831143






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f259227%2fchange-add-to-cart-text-for-not-registered-users%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Mario Kart Wii

                              What does “Dominus providebit” mean?

                              Antonio Litta Visconti Arese