Removing Recently Viewed Products from Magento Product Page
As an experienced developer, I understand your frustration when trying to remove recently viewed products from the Magento product page. Let’s dive into how you can achieve this by editing the core template file.
Understanding the Recently Viewed Products Feature
Magento’s default theme includes a block that displays recently viewed products on the product view page. This is part of the core functionality and cannot be removed through local.xml or layout updates alone.
The recently viewed products are managed by the core/recently_viewed session variable, which stores the IDs of the most recently visited products. When you view a product, its ID gets added to this list until it reaches the configured limit (15 by default).
Editing the Core Template File
To remove the recently viewed products completely, we need to edit the core template file that renders them.
- Navigate to your Magento installation directory via SSH or FTP.
- Locate and open the
app/design/frontend/<your_theme>/template/catalog/product/view.phtmlfile in a text editor.
The <your_theme> placeholder should be replaced with the name of your current theme, such as ‘Magento Blank’ or a custom theme you’re using.
- In this file, look for the following block of code:
<div class="block-products-viewed">
<div class="block-title">
<strong><?= /* @escapeNotAllowed */ $this->__('Recently Viewed Products?') ?></strong>
</div>
<?= /* @escapeNotAllowed */ $block->getProductsHtml() ?>
</div>
- Delete or comment out the entire block of code by adding
//at the beginning of each line.
Your final edited section should look like this:
// <div class="block-products-viewed">
// <div class="block-title">
// <strong><?= /* @escapeNotAllowed */ $this->__('Recently Viewed Products?') ?></strong>
// </div>
// <?= /* @escapeNotAllowed */ $block->getProductsHtml() ?>
// </div>
Clear Cache and Reindex
After making the changes, save the file and clear your Magento cache to ensure the changes take effect immediately.
- In your Magento admin panel, navigate to “System” > “Cache Management”.
- Click the “Flush Magento Cache” button.
Additionally, reindex all indexes by going to “System” > “Index Management” and running all profiles that have status “Reindex Required”.
Conclusion
Removing recently viewed products from the product page in Magento requires editing the core template file directly. While this isn’t ideal for long-term development, it provides a quick solution when needed.
Remember, modifying core files should be done with caution, as updates or theme changes may overwrite your customizations. For a more robust and maintainable solution, consider creating a custom module that extends or replaces the necessary functionality.
For further assistance with Magento customizations and other e-commerce challenges, feel free to explore the resources available at Laravel Company. We specialize in providing high-quality articles and guides on various web development topics.