WooCommerce Code Reference

WC_Comments

Comments class.

Table of Contents

add_avatar_for_review_comment_type()  : array<string|int, mixed>
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.
add_review_comment_filter()  : array<string|int, mixed>
Add Product Reviews filter for `review` comment type.
check_comment_rating()  : array<string|int, mixed>
Validate the comment ratings.
clear_transients()  : mixed
Ensure product average rating and review count is kept up to date.
comment_moderation_recipients()  : array<string|int, mixed>
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<string|int, mixed>
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<string|int, mixed>
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()  : array<string|int, 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.
get_review_counts_for_product_ids()  : array<string|int, mixed>
Utility function for getting review counts for multiple products in one query. This is not cached.
init()  : mixed
Hook in methods.
update_comment_type()  : array<string|int, mixed>
Update comment type of product reviews.
validate_product_review_verified_owners()  : mixed
Validate product reviews if requires a verified owner.
wp_count_comments()  : object
Remove order notes, webhook delivery logs, and product reviews 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<string|int, mixed> $comment_types) : array<string|int, mixed>
Parameters
$comment_types : array<string|int, mixed>

Comment types.

Tags
since
2.3
Return values
array<string|int, mixed>

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

add_review_comment_filter()

Add Product Reviews filter for `review` comment type.

public static add_review_comment_filter(array<string|int, mixed> $comment_types) : array<string|int, mixed>
Parameters
$comment_types : array<string|int, mixed>

Array of comment type labels keyed by their name.

Tags
since
6.0.0
Return values
array<string|int, mixed>

check_comment_rating()

Validate the comment ratings.

public static check_comment_rating(array<string|int, mixed> $comment_data) : array<string|int, mixed>
Parameters
$comment_data : array<string|int, mixed>

Comment data.

Return values
array<string|int, mixed>

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<string|int, mixed> $emails, int $comment_id) : array<string|int, mixed>
Parameters
$emails : array<string|int, mixed>

Emails.

$comment_id : int

Comment ID.

Return values
array<string|int, mixed>

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<string|int, mixed> $clauses) : array<string|int, mixed>

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<string|int, mixed>

A compacted array of comment query clauses.

Return values
array<string|int, mixed>

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<string|int, mixed> $clauses) : array<string|int, mixed>
Parameters
$clauses : array<string|int, mixed>

A compacted array of comment query clauses.

Tags
since
2.2
Return values
array<string|int, mixed>

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) : array<string|int, int>
Parameters
$product : WC_Product

Product instance.

Tags
since
3.0.0
Return values
array<string|int, 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

get_review_counts_for_product_ids()

Utility function for getting review counts for multiple products in one query. This is not cached.

public static get_review_counts_for_product_ids(array<string|int, mixed> $product_ids) : array<string|int, mixed>
Parameters
$product_ids : array<string|int, mixed>

Array of product IDs.

Tags
since
5.0.0
Return values
array<string|int, mixed>

update_comment_type()

Update comment type of product reviews.

public static update_comment_type(array<string|int, mixed> $comment_data) : array<string|int, mixed>
Parameters
$comment_data : array<string|int, mixed>

Comment data.

Tags
since
3.5.0
Return values
array<string|int, mixed>

validate_product_review_verified_owners()

Validate product reviews if requires a verified owner.

public static validate_product_review_verified_owners(int $comment_post_id) : mixed
Parameters
$comment_post_id : int

Post ID.

Return values
mixed

wp_count_comments()

Remove order notes, webhook delivery logs, and product reviews 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