I've create a module and overriden addtocart.phtml to replace the 'Add to Cart' button with 'Preorder' when the Preorder attribute is set to 'Yes'.

This works well on simple products, but I cannot override the button on configurable products (products with options).

Template hints show the following on the add to cart button for simple products:


Configurable shows: /var/www/html/magento/var/view_preprocessed/pub/static/vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

I'm not really sure what is going on here, I can see the path is slightly different but I have no luck when trying to override that file.

Any help would be appreciated.

Cheers, Max

  • I assume you're aware that the path is different because the simple products have the path to your module? – Haim Oct 24 '18 at 3:22

try this -

First clear your var/cache folder using command

rm -rf var/cache/* var/cache/view_preprocessed/*.

Now check template path using path hint for both type products.

In default magento addtocart button is rendered from template file for both simple and configurable products


You need to check catalog_product_view.xml layout file where template file is defined for both type of products.

In this xml, this code is used for simple products-

<block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/>  

and this code is used for configurable products template file --

<block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart.additional" as="product.info.addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/>

as you can see for both type of products same file addtocart.phtml is being used.

So check this xml file for your theme, might be different template file are set there for both type of products

  • Thank you, this was perfect. It turns out I had forgotten to specify configurable products in catalog_product_view.xml. Appreciate your help. – Max Oct 24 '18 at 4:23
  • Your welcome @Max :) – Shashank Kumrawat Oct 24 '18 at 4:43

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.