/** * Replacement for the product FAQ FluentSnippet. * Keeps the existing questions_reponses meta and FAQPage JSON-LD output. */ add_filter( 'woocommerce_structured_data_product', function ( $markup, $product ) { if ( is_a( $product, 'WC_Product' ) ) { $markup['@id'] = get_permalink( $product->get_id() ) . '#product'; } return $markup; }, 10, 2 ); add_shortcode( 'faq_schema', 'fs_product_faq_schema_shortcode' ); if ( ! function_exists( 'fs_product_faq_schema_shortcode' ) ) { function fs_product_faq_schema_shortcode( $atts ) { if ( ! function_exists( 'is_product' ) || ! is_product() ) { return ''; } global $post; $items = get_post_meta( $post->ID, 'questions_reponses', true ); if ( empty( $items ) || ! is_array( $items ) ) { return '

Es gibt derzeit keine weiteren Kundenfragen.

'; } $css = ''; $js = ''; $schema = array( '@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => array(), ); $html = $css . '
'; $valid_index = 0; foreach ( $items as $item ) { $question = isset( $item['questions'] ) ? trim( wp_strip_all_tags( $item['questions'] ) ) : ''; $answer = isset( $item['reponses'] ) ? trim( $item['reponses'] ) : ''; if ( '' === $question || '' === $answer ) { continue; } $answer_html = wpautop( wp_kses_post( $answer ) ); $is_open = 0 === $valid_index; $button_id = 'product-faq-button-' . $post->ID . '-' . $valid_index; $panel_id = 'product-faq-panel-' . $post->ID . '-' . $valid_index; $html .= '
'; $html .= '

'; $html .= '

'; $html .= '
'; $html .= '
' . $answer_html . '
'; $schema['mainEntity'][] = array( '@type' => 'Question', 'name' => $question, 'acceptedAnswer' => array( '@type' => 'Answer', 'text' => trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( $answer_html ) ) ), ), ); $valid_index++; } $html .= '
' . $js; if ( empty( $schema['mainEntity'] ) ) { return $html . '

Es gibt derzeit keine weiteren Kundenfragen.

'; } return $html . "\n"; } }