Pro vývojáře
Meta data komentáře
Section titled “Meta data komentáře”_wpify_woo_details
Section titled “_wpify_woo_details”Typ komentáře se ukládá do comment meta:
$details = get_comment_meta( $comment_id, '_wpify_woo_details', true );
// Struktura:// [// 'type' => 'uuid-1234-5678' // ID typu z nastavení// ]Získání názvu typu
Section titled “Získání názvu typu”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 pro zobrazení typu
Section titled “Hook pro zobrazení typu”Modul používá akci woocommerce_review_meta:
add_action( 'woocommerce_review_meta', function( $comment ) { // Vlastní zobrazení typu}, 15 ); // Po modulu (výchozí priorita 10)Příklad: Vlastní stylování
Section titled “Příklad: Vlastní stylování”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 );Příklad: Přidání typu programově
Section titled “Příklad: Přidání typu programově”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 );}
// Použitíset_comment_type( 123, 'uuid-verified-purchase' );Příklad: Filtrování recenzí podle typu
Section titled “Příklad: Filtrování recenzí podle typu”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 třídy
Section titled “CSS třídy”| Třída | Popis |
|---|---|
.woocommerce-review__type | Element s typem recenze |
/* Příklad stylování */.woocommerce-review__type { background: #0073aa; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 12px;}