I wonder if it could be an issue on your comment-approval settings? If I remember right, the admin and the post/product author get the approval email, and just the post author gets the final “new comment” email.
I mention that because in my quick test with comments automatically approved, the product author got the (sole) notification email. I didn’t strip out plugins like you did though, so maybe one of them is altering the behavior on my end.
Thanks a lot for your comment, that helped to get me on the right track 🙂
So my settings before were:
Email me whenever:
- Anyone posts a comment -> yes
- A comment is held for moderation -> yes
Before a comment appears:
- Comment must be manually approved -> no
- Comment author must have a previously approved comment -> yes
Resulting in the behaviour I described in my first post: The “moderation/approval” mail for products is not sent to the author (and the “new comment” email is never sent – but that makes sense).
Now I disabled “Comment author must have a previously approved comment” – meaning the comments are automatically approved.
In this case yes, as you said, the post/product author gets the “new comment” email – but not the site admin. But as I don’t want the comments to be automatically approved, not really helpful.
In short: This is completely confusing and opaque (and I searched now for quite some time for a clear explanation) 😉
Anyway, while I would still like to know why WordPress and WooCommerce behave differently, here the solution I used:
function new_comment_moderation_recipients( $emails, $comment_id ) {
return array( 'example@example.com' );
}
add_filter( 'comment_moderation_recipients', 'new_comment_moderation_recipients', 24, 2 );
add_filter( 'comment_notification_recipients', 'new_comment_moderation_recipients', 24, 2 );
This code overwrites the recipient for every comment notification mail.
Maybe that helps somebody else too 🙂
Hey @nailedit (great username, by the way),
It looks like you got an answer to this through a StackExchange post? Do you still need help with this?
https://stackoverflow.com/questions/30887565/notify-email-when-someones-posted-a-review-in-woocommerce
Hi @shellbeezy
Yes, that was the post, forgot to link to it.
Well, while I found this workaround, my original question was still open: Why does WordPress send the moderation notification email to the site admin and post author, while WooCommerce only sends it to the site admin?
Especially because most people say it should work the same way (e.g. also in the StackExchange link).
Well I finally wanted to know for sure and looked into the WooCommerce source code. If I’m not wrong, I found the answer:
- Yes: The “new comment” notification mail (the “comment_notification_recipients” filter) works in WordPress and WooCommerce the same way.
- BUT: The (at least for me) more important “comment moderation” notification mail (the “comment_moderation_recipients” filter) does not work the same way. WooCommerce overwrites the recipient and sends it only to the site admin, not the product author. See the code below:
public static function comment_moderation_recipients( $emails, $comment_id ) {
$comment = get_comment( $comment_id );
if ( $comment && 'product' === get_post_type( $comment->comment_post_ID ) ) {
$emails = array( get_option( 'admin_email' ) );
}
return $emails;
}
See: https://github.com/woocommerce/woocommerce/blob/762f05108091511d6464e392f75883e05b15d930/includes/class-wc-comments.php
So yes, I now have the answer and I’ll go ahead an mark this thread as resolved 🙂
Hey @nailedit,
Nice work tracking down the code responsible, it may help others that find this thread in the future. 🙂
Cheers!