Automattic\WooCommerce\Internal\PushNotifications\Triggers
NewReviewNotificationTrigger::on_comment_post
Handles the comment_post hook.
Only creates a notification for non-spam reviews on products.
Method of the class: NewReviewNotificationTrigger{}
No Hooks.
Returns
null. Nothing (null).
Usage
$NewReviewNotificationTrigger = new NewReviewNotificationTrigger(); $NewReviewNotificationTrigger->on_comment_post( $comment_id, $comment_approved, $commentdata ): void;
- $comment_id(int) (required)
- The comment ID.
- $comment_approved(int|string) (required)
- 1 if approved, 0 if not,
'spam'if spam. - $commentdata(array) (required)
- The comment data.
Changelog
| Since 10.7.0 | Introduced. |
NewReviewNotificationTrigger::on_comment_post() NewReviewNotificationTrigger::on comment post code WC 10.8.1
public function on_comment_post( int $comment_id, $comment_approved, array $commentdata ): void {
if (
'spam' === $comment_approved
|| 'review' !== ( $commentdata['comment_type'] ?? '' )
) {
return;
}
$commented_on = get_post_type( (int) ( $commentdata['comment_post_ID'] ?? 0 ) );
if ( 'product' !== $commented_on ) {
return;
}
wc_get_container()->get( PendingNotificationStore::class )->add(
new NewReviewNotification( $comment_id )
);
}