WooCommerce Code Reference

WC_Comments

Comments class.

Table of Contents

add_avatar_for_review_comment_type()  : array
Make sure WP displays avatars for comments with the `review` type.
add_comment_purchase_verification()  : bool
Determine if a review is from a verified owner at submission.
add_comment_rating()  : mixed
Rating field for comments.
check_comment_rating()  : array
Validate the comment ratings.
clear_transients()  : mixed
Ensure product average rating and review count is kept up to date.
comment_moderation_recipients()  : array
Modify recipient of review email.
comments_open()  : bool
See if comments are open.
delete_comments_count_cache()  : mixed
Delete comments count cache whenever there is new comment or the status of a comment changes. Cache will be regenerated next time WC_Comments::wp_count_comments() is called.
exclude_order_comments()  : array
Exclude order comments from queries and RSS.
exclude_order_comments_from_feed_join()  : mixed
Exclude order comments from feed.
exclude_order_comments_from_feed_where()  : string
Exclude order comments from queries and RSS.
exclude_webhook_comments()  : array
Exclude webhook comments from queries and RSS.
exclude_webhook_comments_from_feed_join()  : mixed
Exclude webhooks comments from feed.
exclude_webhook_comments_from_feed_where()  : string
Exclude webhook comments from queries and RSS.
get_average_rating_for_product()  : float
Get product rating for a product. Please note this is not cached.
get_rating_counts_for_product()  : int[]
Get product rating count for a product. Please note this is not cached.
get_review_count_for_product()  : int
Get product review count for a product (not replies). Please note this is not cached.
init()  : mixed
Hook in methods.
update_comment_type()  : array
Update comment type of product reviews.
wp_count_comments()  : object
Remove order notes and webhook delivery logs from wp_count_comments().
is_default_comment_type()  : bool
Determines if a comment is of the default type.

Methods

add_avatar_for_review_comment_type()

Make sure WP displays avatars for comments with the `review` type.

public static add_avatar_for_review_comment_type(array $comment_types) : array
Parameters
$comment_types : array

Comment types.

Tags
since
2.3
Return values
array

add_comment_purchase_verification()

Determine if a review is from a verified owner at submission.

public static add_comment_purchase_verification(int $comment_id) : bool
Parameters
$comment_id : int

Comment ID.

Return values
bool

add_comment_rating()

Rating field for comments.

public static add_comment_rating(int $comment_id) : mixed
Parameters
$comment_id : int

Comment ID.

Return values
mixed

check_comment_rating()

Validate the comment ratings.

public static check_comment_rating(array $comment_data) : array
Parameters
$comment_data : array

Comment data.

Return values
array

clear_transients()

Ensure product average rating and review count is kept up to date.

public static clear_transients(int $post_id) : mixed
Parameters
$post_id : int

Post ID.

Return values
mixed

comment_moderation_recipients()

Modify recipient of review email.

public static comment_moderation_recipients(array $emails, int $comment_id) : array
Parameters
$emails : array

Emails.

$comment_id : int

Comment ID.

Return values
array

comments_open()

See if comments are open.

public static comments_open(bool $open, int $post_id) : bool
Parameters
$open : bool

Whether the current post is open for comments.

$post_id : int

Post ID.

Tags
since
3.1.0
Return values
bool

delete_comments_count_cache()

Delete comments count cache whenever there is new comment or the status of a comment changes. Cache will be regenerated next time WC_Comments::wp_count_comments() is called.

public static delete_comments_count_cache() : mixed
Return values
mixed

exclude_order_comments()

Exclude order comments from queries and RSS.

public static exclude_order_comments(array $clauses) : array

This code should exclude shop_order comments from queries. Some queries (like the recent comments widget on the dashboard) are hardcoded. and are not filtered, however, the code current_user_can( 'read_post', $comment->comment_post_ID ) should keep them safe since only admin and. shop managers can view orders anyway.

The frontend view order pages get around this filter by using remove_filter('comments_clauses', array( 'WC_Comments' ,'exclude_order_comments'), 10, 1 );

Parameters
$clauses : array

A compacted array of comment query clauses.

Return values
array

exclude_order_comments_from_feed_join()

Exclude order comments from feed.

public static exclude_order_comments_from_feed_join(mixed $join) : mixed
Parameters
$join : mixed

Deprecated.

Tags
deprecated
3.1
Return values
mixed

exclude_order_comments_from_feed_where()

Exclude order comments from queries and RSS.

public static exclude_order_comments_from_feed_where(string $where) : string
Parameters
$where : string

The WHERE clause of the query.

Return values
string

exclude_webhook_comments()

Exclude webhook comments from queries and RSS.

public static exclude_webhook_comments(array $clauses) : array
Parameters
$clauses : array

A compacted array of comment query clauses.

Tags
since
2.2
Return values
array

exclude_webhook_comments_from_feed_join()

Exclude webhooks comments from feed.

public static exclude_webhook_comments_from_feed_join(mixed $join) : mixed
Parameters
$join : mixed

Deprecated.

Tags
deprecated
3.1
Return values
mixed

exclude_webhook_comments_from_feed_where()

Exclude webhook comments from queries and RSS.

public static exclude_webhook_comments_from_feed_where(string $where) : string
Parameters
$where : string

The WHERE clause of the query.

Tags
since
2.1
Return values
string

get_average_rating_for_product()

Get product rating for a product. Please note this is not cached.

public static get_average_rating_for_product(WC_Product &$product) : float
Parameters
$product : WC_Product

Product instance.

Tags
since
3.0.0
Return values
float

get_rating_counts_for_product()

Get product rating count for a product. Please note this is not cached.

public static get_rating_counts_for_product(WC_Product &$product) : int[]
Parameters
$product : WC_Product

Product instance.

Tags
since
3.0.0
Return values
int[]

get_review_count_for_product()

Get product review count for a product (not replies). Please note this is not cached.

public static get_review_count_for_product(WC_Product &$product) : int
Parameters
$product : WC_Product

Product instance.

Tags
since
3.0.0
Return values
int

update_comment_type()

Update comment type of product reviews.

public static update_comment_type(array $comment_data) : array
Parameters
$comment_data : array

Comment data.

Tags
since
3.5.0
Return values
array

wp_count_comments()

Remove order notes and webhook delivery logs from wp_count_comments().

public static wp_count_comments(object $stats, int $post_id) : object
Parameters
$stats : object

Comment stats.

$post_id : int

Post ID.

Tags
since
2.2
Return values
object

is_default_comment_type()

Determines if a comment is of the default type.

private static is_default_comment_type(string $comment_type) : bool

Prior to WordPress 5.5, '' was the default comment type. As of 5.5, the default type is 'comment'.

Parameters
$comment_type : string

Comment type.

Tags
since
4.3.0
Return values
bool