In today’s digital era, there are numerous stores all around us including both online and offline. However, shoppers consider several factors before making a purchase like the product brand, quality, features, price and most importantly review from the customers who have already purchased in past. These product reviews are powerful enough to make or break any business. Because it helps customers know the product & brand more clearly and differentiate it from other stores. For store owner, it’s key to success for building a long-lasting relationship with new customers because 92 percent of customers read & consider store product reviews before making their mind.
Also. Managing customer reviews from the store backend require attention and time but when it comes from a registered shopper we don’t need to worry more because it is completely based on their shopping experience and generally we can’t decline it. But by default in Magento 2, we need to manually approve customer reviews from the store backend. But what if we can automate this process to our save time and efforts.
Yes! Here we go, back with another blog for automatically approve registered store customer product reviews in Magento 2.
Firstly, we need to create an event using ‘events.xml that will trigger each time before saving the review.
app\code\Vendor\Extension\etc\frontend\events.xml
<pre class="lang:default decode:true"> <?xml version="1.0" encoding="utf-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="review_save_before"> <observer name="vendor_extension_review_auto_approve" instance=" Vendor\Extension\Observer\Autoreview "/> </event> </config> </pre>
After that create another file ‘Autoreview.php‘ inside your custom extension folder to set review status as approved.
app\code\Vendor\Extension\Observer\Autoreview.php
<pre class="lang:default decode:true"> <?php namespace Vendor\ Extension\Observer; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Review\Model\Review; class Autoreview implements ObserverInterface { public function execute(Observer $observer) { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) { $review = $observer->getDataByKey('object'); $review->setStatusId(Review::STATUS_APPROVED); } } } </pre>
You can use this code inside your Magento 2 store for automate the process of accepting reviews from your registered store customer.
Lastly, smash that stars if the code worked for you and don’t forget to comment down below if you are looking for any help regarding this code.
Happy Coding.
Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…