WooCommerce: Notify Admin For Product Reviews But Not For WordPress Comments

WooCommerce product reviews are, actually, WordPress comments.

When you install WordPress, comment notifications for admins are turned on. You can choose to receive emails for all new comments, or only for comments that require moderation (haven’t been approved yet).

The problem is that if your site gets a lot of spam comments, you might be bombarded with emails. Even with legitimate comments, constant notifications can be overwhelming.

So what if we disable WordPress comment notifications all together, while we keep them enabled for WooCommerce product reviews only?

This is what we’ll code today – enjoy!

When this setting is enabled, you will receive a notification for each WP comment. This is great, until you get hundreds a day… So, leave this option enabled but couple it with the snippet below – and you will only get notified when a WooCommerce review (WP comment) is held for moderation!

PHP Snippet: Disable WP Comment Notifications… Except WooCommerce Product Reviews

/**
 * @snippet       Disable WP Comment Notifications Except Woo Reviews
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'notify_moderator', 'bbloomer_only_woo_comment_notifications', 9999, 2 );

function bbloomer_only_woo_comment_notifications( $maybe_notify, $comment_id ) {
	 $review = get_comment( $comment_id );
    if ( $review && 'product' === get_post_type( $review->comment_post_ID ) ) return true; // DO EMAIL PRODUCT REVIEW
	 return false; // DO NOT EMAIL WP COMMENT
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *