How to get recently viewed products on the category page in Magento 2

If you want to show recently viewed products on the category listing page, follow these steps:

1. First of all overide the catalog_category_view.xml file in theme if not present.

2. And then paste following code in this file:
<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>

<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="recentview" after="-">
                    <arguments>
                        <argument name="block_id" xsi:type="string">recently_viewed</argument>
                    </arguments>
                </block>
 </referenceContainer>

</body>
</page>
3. If the catalog_category_view.xml file is present in theme, add the following code in this file:
<block class="Magento\Cms\Block\Block" name="recentview" after="-">
                    <arguments>
                        <argument name="block_id" xsi:type="string">recently_viewed</argument>
                    </arguments>
                </block>
4. Then run the following command in your root directory to flush cache:
php bin/magento c:f

Now you can see recently viewed products on the category page.

How to get recently viewed products on the category page in Magento 2.expoundsofttechsolution


How to get recently viewed products on the category page in Magento 2