{"id":514,"date":"2019-07-19T12:03:47","date_gmt":"2019-07-19T12:03:47","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/07\/19\/auto-approve-product-review-for-registered-customers-in-magento-2\/"},"modified":"2025-03-18T04:57:38","modified_gmt":"2025-03-18T04:57:38","slug":"auto-approve-product-review-for-registered-customers-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/auto-approve-product-review-for-registered-customers-in-magento-2\/","title":{"rendered":"How to Auto Approve Product Review For Registered Customers in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Customer Reviews are important and these statistics from&nbsp;<a href=\"https:\/\/www.invespcro.com\/blog\/the-importance-of-online-customer-reviews-infographic\/\" target=\"_blank\" rel=\"noreferrer noopener\">Invespcro<\/a>&nbsp;just shows how much:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Customers are likely to spend<strong>&nbsp;<\/strong>31% more with a business that has \u201cexcellent\u201d reviews.<\/li>\n\n\n\n<li>72% of consumers will take action only after reading a positive review.<\/li>\n\n\n\n<li>79% of <a href=\"https:\/\/meetanshi.com\/blog\/online-review-statistics\/\">consumers trust online reviews<\/a> as much as personal recommendations.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Whether it is about finding a restaurant, selecting a phone, or choosing software for your business, reviews have a big role to play in the purchase decision.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Magento 2, which is a platform for shopping variety of products, managing customer reviews can\u2019t be just a low priority task. Unfortunately, Magento 2, by default, does not offer a system to automate the review approvals. When it comes to the product reviews by the registered customers, there is no need to look into it before making them live as they write genuinely without being bots! However, with a pile of work that admin has, approving a customer review to be displayed in the frontend, one by one, as it comes, is not feasible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hence, I have implemented a programmatic solution to&nbsp;<em><strong>auto approve product review for registered customers in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reviews from registered customers can be considered genuine and flaunting them on the frontend only helps you leverage the below benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Helps in analyzing and understanding the customers to improve customer service.<\/li>\n\n\n\n<li>Credibility and social proof!<\/li>\n\n\n\n<li>Leave a positive impression on potential customers with excellent reviews<\/li>\n\n\n\n<li>Create customer loyalty<\/li>\n\n\n\n<li>Improve rankings<\/li>\n\n\n\n<li>Use this user-generated content for marketing<\/li>\n\n\n\n<li>Customer engagement<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The solution not only auto approves registered customers\u2019 product reviews but also automatically send a \u201cthank you\u201d Email with a custom message. Acknowledging the customers\u2019 efforts immediately is only the right thing to do! Again, automating it saves admin\u2019s time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Easily enjoy these benefits without having to manage the customer reviews manually in your Magento 2 store with the below solution:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Auto Approve Product Review For Registered Customers in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create<strong>&nbsp;registration.php<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Meetanshi_CustomModule',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>module.xml<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/etc<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\">\n    &lt;module name=\"Meetanshi_CustomModule\" setup_version=\"1.0.0\"\/>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create&nbsp;<strong>events.xml<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/etc\/frontend<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Event\/etc\/events.xsd\">\n    &lt;event name=\"review_save_before\">\n        &lt;observer name=\"review_auto_approve\" instance=\"Meetanshi\\CustomModule\\Observer\\ReviewApproveBefore\"\/>\n    &lt;\/event>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create&nbsp;<strong>email_templates.xml<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/etc<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:Magento:module:Magento_Email:etc\/email_templates.xsd\">\n    &lt;template id=\"meetanshi_review_template\" label=\"Auto Approve Review email\" file=\"CustomModule\/review.html\" type=\"html\" module=\"Meetanshi_CustomModule\" area=\"frontend\"\/>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Create&nbsp;<strong>review.html<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/view\/frontend\/email\/CustomModule<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!--@subject Thank You For Your Review  @-->\n&lt;!--@vars {\n\"var var1\":\"Customer Name\"\n} @-->\n\n{{template config_path=\"design\/email\/header_template\"}}\n\n&lt;!-- here $var1 , $var2, are variables in which we\n    assign values when we use this template for send mail-->\n\n&lt;!-- you can Modify content of template according to your requirement-->\n&lt;table>\n    &lt;tr class=\"email-intro\">\n        &lt;td>\n            &lt;p class=\"greeting\">{{trans \"%customer_name,\" customer_name=$var1}}&lt;\/p>\n            &lt;p>\n                {{trans \"Your custom message.\"}}\n            &lt;\/p>\n        &lt;\/td>\n    &lt;\/tr>\n&lt;\/table>\n\n{{template config_path=\"design\/email\/footer_template\"}}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6. Create&nbsp;<strong>ReviewApproveBefore.php<\/strong>&nbsp;file at&nbsp;<em><strong>Meetanshi\/CustomModule\/Observer<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Meetanshi\\CustomModule\\Observer;\n\nuse Magento\\Framework\\Event\\Observer;\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\Review\\Model\\Review;\n\nclass ReviewApproveBefore implements ObserverInterface\n{\n    private $customerSession;\n    private $request;\n    private $transportBuilder;\n    private $storeManager;\n\n    public function __construct(\n        \\Magento\\Customer\\Model\\Session $customerSession,\n        \\Magento\\Framework\\App\\Request\\Http $request,\n        \\Magento\\Framework\\Mail\\Template\\TransportBuilder $transportBuilder,\n        \\Magento\\Store\\Model\\StoreManagerInterface $storeManager\n    ){\n        $this->customerSession = $customerSession;\n        $this->request = $request;\n        $this->transportBuilder = $transportBuilder;\n        $this->storeManager = $storeManager;\n    }\n    public function execute(Observer $observer)\n    {\n        if($this->customerSession->isLoggedIn()) {\n            $review = $observer->getDataByKey('object');\n            $review->setStatusId(Review::STATUS_APPROVED); \/\/ set status approve\n\n            try {\n                $store = $this->storeManager->getStore()->getId();\n                $transport = $this->transportBuilder->setTemplateIdentifier('meetanshi_review_template') \/\/ get template id from email_template.xml\n                    ->setTemplateOptions(['area' => 'frontend', 'store' => $store])\n                    ->setTemplateVars(\n                        [\n                            'store' => $this->storeManager->getStore(),\n                            'var1' => $this->customerSession->getCustomerData()->getFirstname(), \/\/var1 variable used in review.html\n                        ]\n                    )\n                    ->setFrom('general')\n                    \/\/ you can config general email address in Store -> Configuration -> General -> Store Email Addresses\n                    ->addTo($this->customerSession->getCustomerData()->getEmail(), $this->customerSession->getCustomerData()->getFirstname())\n                    ->getTransport();\n                $transport->sendMessage();\n            }catch (\\Exception $e){\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That was all about auto approving registered customers\u2019 product reviews to be showcased in the frontend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Customer reviews are here to stay, and the longer you wait to start leveraging them, the more you stand to lose.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Found the post helpful? Have any doubts? Feel free to write a comment below!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Customer Reviews are important and these statistics from&nbsp;Invespcro&nbsp;just shows how much: Whether it is about finding a restaurant, selecting a phone, or choosing software for&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-514","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":10102,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/514\/revisions\/10102"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}