Hello Friends ,
You know by default magento allow all guest or customer to give review on all products. but for my client requirement to give review on only purchased products i have created small code. here I’m going to share with you all.you can implement this code on view.php of theme file.
Here is code
<?php
$purcashed_products_id[] = array();
if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {
$orders= Mage::getModel(‘sales/order’)->getCollection()->addAttributeToFilter(‘customer_id’,23);
foreach($orders as $eachOrder){
$order = Mage::getModel(“sales/order”)->load($eachOrder->getId());
$items = $order->getAllVisibleItems();
foreach($items as $item):
$purcashed_products_id[] = $item->getProductId();
endforeach;
}
}
if (in_array($Current_product_id,$purcashed_products_id)) {?>
<?php echo $this->getChildHtml(‘product_reviews’); ?>
<?php }
?>
For more information on add review only, feel free to reach out to our team.
Is Your Magento Store Secure?
Vulnerabilities like CosmicSting and SessionReaper are actively exploited. Scan your website in seconds to detect malware, exposed endpoints, and missing patches.
Run Free Security Scan on MageArgus →
Fact-Checked & Verified by W3ctrl
This content has been written and reviewed by Adobe-Certified Technical Experts with over 16 years of experience in Enterprise Architecture.
