5

I want to add guaranty (custom product attribute) to customers wish-list page that is in customer dashboard in my Wishlist tab. Means that I wanted to show price, qty, name, guaranty, and add to basket into the products section in customers Wishlist tab.

I am using Magento 2.1.

How can I do that?

3
  • can you please elaborate your question a little more with some image or some code content so that someone can help you better Mar 19 '19 at 6:28
  • Yes! i want to add guaranty attribute that is my custom attribute to my wishlist page in customer panel my wishlist tab. means that i want to show price qty name guaranty and add to basket into my products who are in my wishlist tab
    – MGPM
    Mar 19 '19 at 7:59
  • @MGPM guaranty is product attribute or custom option ? Mar 19 '19 at 11:29
1

To show the custom attribute value on the wishlist section of customer dashboard do the following thing

  • From admin panel go to the below location

Admin_panel > STORES > Attributes > Products > select the attribute

  • Go to the storefront properties please refer this
  • Look for the Used in Product Listing change it to yes please refer this
  • Save the attribute
  • Now copy the name.phtml file from the below location

magento_root/vendor/magento/module-wishlist/view/frontend/templates/item/column/name.phtml

  • Paste it to the below location

magento_root/app/design/frontend/Vendor/theme/Magento_Wishlist/templates/item/column/name.phtml

  • Paste the below code to the newly created name.phtml

name.phtml

<?php if(!empty($product)) : ?>
   <?php $attributeValue = $product->getResource()->getAttribute('attibute_name')->getFrontend()->getValue($product);
   $attributeLabel = $product->getResource()->getAttribute('attibute_name')->getFrontend()->getLabel($product);
   if(!empty($attributeValue)) { ?>
     <h2 class="product-<?php echo $attributeLabel?>"><strong><?php echo __($attributeLabel);?></strong>  <?php echo __($attributeValue); ?></h2>
   <?php } 
endif; ?>

Note: Replace the attribute_name with the name of your attribute that you can copy from the Admin panel.

You can also use some other phtml file but make sure to call it using the layout.xml file for the wishlist you can use wishlist_index_index.xml file

If the content is not loading then to flush the cache run the below command

php bin/magento cache:flush

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.