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

1
  • You can copy the addtocart.phtml from vendor directory and call your custom attribute value according to your requirement. Commented Aug 24, 2018 at 8:58

1 Answer 1

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

4
  • 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. Commented Aug 24, 2018 at 10:17
  • Did you copy the file to app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/addtocart.phtml location? Commented Aug 24, 2018 at 10:27
  • yes brother, i just figuredout. i copied at vendor location. thank you. please updae the answer with your above comment. Commented Aug 24, 2018 at 10:44
  • Yes. Its updated now. Commented Aug 24, 2018 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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