Skip to content

For Developers

The comment type is stored in comment meta:

$details = get_comment_meta( $comment_id, '_wpify_woo_details', true );
// Structure:
// [
// 'type' => 'uuid-1234-5678' // Type ID from settings
// ]
function get_comment_type_label( $comment_id ) {
$details = get_comment_meta( $comment_id, '_wpify_woo_details', true );
if ( empty( $details['type'] ) ) {
return null;
}
$module = wpify_woo_container()->get(
\WpifyWoo\Modules\Comments\CommentsModule::class
);
$comment_types = $module->get_setting( 'comment_types' ) ?: [];
foreach ( $comment_types as $type ) {
if ( $type['id'] === $details['type'] ) {
return $type['label'];
}
}
return null;
}

The module uses the woocommerce_review_meta action:

add_action( 'woocommerce_review_meta', function( $comment ) {
// Custom type display
}, 15 ); // After the module (default priority 10)
add_action( 'woocommerce_review_meta', function( $comment ) {
$details = get_comment_meta( $comment->comment_ID, '_wpify_woo_details', true );
if ( empty( $details['type'] ) ) {
return;
}
$module = wpify_woo_container()->get(
\WpifyWoo\Modules\Comments\CommentsModule::class
);
$comment_types = $module->get_setting( 'comment_types' ) ?: [];
foreach ( $comment_types as $type ) {
if ( $type['id'] === $details['type'] ) {
printf(
'<span class="review-badge review-badge--%s">%s</span>',
sanitize_html_class( $type['id'] ),
esc_html( $type['label'] )
);
break;
}
}
}, 15 );
function set_comment_type( $comment_id, $type_id ) {
$details = get_comment_meta( $comment_id, '_wpify_woo_details', true ) ?: [];
$details['type'] = $type_id;
update_comment_meta( $comment_id, '_wpify_woo_details', $details );
}
// Usage
set_comment_type( 123, 'uuid-verified-purchase' );
function get_reviews_by_type( $product_id, $type_id ) {
$comments = get_comments( [
'post_id' => $product_id,
'type' => 'review',
'status' => 'approve',
] );
$filtered = [];
foreach ( $comments as $comment ) {
$details = get_comment_meta( $comment->comment_ID, '_wpify_woo_details', true );
if ( ! empty( $details['type'] ) && $details['type'] === $type_id ) {
$filtered[] = $comment;
}
}
return $filtered;
}
ClassDescription
.woocommerce-review__typeReview type element
/* Styling example */
.woocommerce-review__type {
background: #0073aa;
color: #fff;
padding: 2px 8px;
border-radius: 3px;
font-size: 12px;
}