3

I have create drop-down attribute on the name of location with drop-down options.

I'd like to show the value of this attribute at product details page above add to cart.

Copied the file addtocart.phtml from the below location:

vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

to my theme like below:

app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml

I added my attribute code for my custom attribute like below :

<?= $_product->getAttributeText('location'); ?> //For dropdown

But it is not showing the data.

My product's url is :

http://www.depoto.com/vizag/sample-one.html

  • You can copy the addtocart.phtml from vendor directory and call your custom attribute value according to your requirement. – Sukumar Gorai Aug 24 '18 at 8:58
2

Copy the file addtocart.phtml from the below location:

vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

to your theme like below:

app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml

Then you can add your code for your custom attribute like below :

<?= $_product->getAttributeText('attribute_code'); ?> //For dropdown
<?= $_product->getData('attribute_code'); ?> //For text

Note: Write your custom code anywhere on this page but after the line <?php $_product = $block->getProduct(); ?>

UPDATED:

As you are using PORTO theme then you need to copy the file to below location:

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/addtocart.phtml

|improve this answer|||||
  • I think you are using theme. Can you check if any other addtocart.phtml is calling from the theme? You can check the exact file name by enabling the template path hint. – Sukumar Gorai Aug 24 '18 at 10:17
  • Did you copy the file to app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/addtocart.phtml location? – Sukumar Gorai Aug 24 '18 at 10:27
  • yes brother, i just figuredout. i copied at vendor location. thank you. please updae the answer with your above comment. – Teja Bhagavan Kollepara Aug 24 '18 at 10:44
  • Yes. Its updated now. – Sukumar Gorai Aug 24 '18 at 10:51

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.