Magento – Magento 2. How to add recently viewed products programmatically

magento-2.0productsview

I have a page with a custom layout and I want to add Recently Viewed Products to one of the blocks on that page. How do I do it programmatically, e.g. using my own phtml template?
In Magento 1.9x it was super easy to do. In Magento 2 this function added using widget, but I cannot find the way to add it to my custom page.
Regards!

Best Answer

You can create a new static block and call it in your phtml file, So do the following step : Navigate Content->Blocks = create a new block and add recently viewed products widget in it and save the block and call in in your phtml file using following code:

<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('your_block_Identifier')->toHtml();?>

clear your cache and refresh the page.

Done !

Related Topic