Automattic\WooCommerce\Internal\PushNotifications\Triggers
NewReviewNotificationTrigger::on_comment_post
Handles the comment_post hook.
Only creates a notification for non-spam reviews on products.
Метод класса: NewReviewNotificationTrigger{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$NewReviewNotificationTrigger = new NewReviewNotificationTrigger(); $NewReviewNotificationTrigger->on_comment_post( $comment_id, $comment_approved, $commentdata ): void;
- $comment_id(int) (обязательный)
- The comment ID.
- $comment_approved(int|строка) (обязательный)
- 1 if approved, 0 if not,
'spam'if spam. - $commentdata(массив) (обязательный)
- The comment data.
Список изменений
| С версии 10.7.0 | Введена. |
Код NewReviewNotificationTrigger::on_comment_post() NewReviewNotificationTrigger::on comment post WC 11.3.0
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 )
);
}