How to show description of the product in wishlist phtml file?

To Display description in wishlist you have to follow the steps given below:

Step 1

Create a new file wishlist_index_index.xml at location: <root>\app\design\frontend\Companyname\Packagename\Magento_Wishlist\layout\wishlist_index_index.xml

<body>
<referenceBlock name="customer.wishlist.items">
<block class="Companyname\Packagename\Block\Description" name="customer.wishlist.item.description" template="Magento_Wishlist::item/column/description.phtml" cacheable="false" after="customer.wishlist.item.name"/>
</referenceBlock>
</body>

Step 2

Create a new file description.phtml at location: <root>\app\design\frontend\Companyname\Packagename\Magento_Wishlist\templates\item\column\description.phtml

<?php 
$item = $block->getItem(); 
$product = $item->getProduct(); 
?> 
<strong class="product-item-description"> 
<?php echo $block->escapeHtml($product->getDescription()) ?> 
</strong>

Step 3

Create a new file Description.php at location: <root>\app\code\Companyname\Packagename\Block\Description.php

<?php
namespace Companyname\Packagename\Block;
class Description extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info
{
 /**
    * @var \Magento\Catalog\Api\ProductRepositoryInterface 
  */
protected $productRepository;

public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\App\Http\Context $httpContext,
array $data = [],
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->productRepository = $productRepository;
parent::__construct($context, $httpContext, $data);
}

public function getDescription()
{
$id = $this->getItem()->getProduct()->getId();
$product = $this->productRepository->getById($id);
return $product->getDescription();
}
}

Note:- Do not make changes in the core files, add it in your theme directory

Step 4

In layout file replace block class from Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info to Companyname\Packagename\Block\Description

After that in your template file, you can get product description using the code given below:

$block->getDescription();

Finally, run the commands given below to make changes effective:

php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy en_US -f
php bin/magento cache:clean
php bin/magento cache:flush
  • Share :