For Developers
Comment Meta Data
Section titled “Comment Meta Data”_wpify_woo_details
Section titled “_wpify_woo_details”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// ]Getting the Type Label
Section titled “Getting the Type Label”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;}Hook for Displaying Type
Section titled “Hook for Displaying Type”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)Example: Custom Styling
Section titled “Example: Custom Styling”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 );Example: Adding Type Programmatically
Section titled “Example: Adding Type Programmatically”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 );}
// Usageset_comment_type( 123, 'uuid-verified-purchase' );Example: Filtering Reviews by Type
Section titled “Example: Filtering Reviews by Type”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;}CSS Classes
Section titled “CSS Classes”| Class | Description |
|---|---|
.woocommerce-review__type | Review type element |
/* Styling example */.woocommerce-review__type { background: #0073aa; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 12px;}