Merchants often prefer to show description of the product directly in the Magento wishlist to improve customer experience. Adding product descriptions lets users recall details quickly without opening the product page, which makes the wishlist more engaging and user-friendly.
To display the description in the wishlist, you have to follow the steps given below:
Step 1
Create a new file wishlist_index_index.xml at the 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
You can easily show description of the product in your Magento wishlist by following these steps This customization improves usability, enables buyers to make quicker purchase decisions, and delivers more value to your store’s shopping experience without altering Magento’s core files.
Feel free to leave your comments below and contact us if you need any help to customize your Magento store.
Happy coding!
Post a Comment
Got a question? Have a feedback? Please feel free to leave your ideas, opinions, and questions in the comments section of our post! ❤️