WPML

문제 개요

WPML과 함께 YITH WooCommerce Advanced Reviews 플러그인을 사용할 때, 번역된 상품에는 원본 상품의 리뷰가 전혀 표시되지 않습니다. 리뷰 탭에는 0개의 리뷰가 표시되며 평점은 없습니다. 상품, 카테고리 또는 태그에 설정된 리뷰 상자 또한 해당 번역에 적용되지 않습니다.

임시 해결 방법

하위 테마의 functions.php 파일이나 소규모 플러그인에 이 코드를 추가하세요.

PHP
add_action( 'pre_get_posts', function ( $q ) {
    if ( ! array_intersect( (array) $q->get( 'post_type' ), [ 'ywar_reviews', 'ywar_review_boxes' ] ) ) { return; }
    $mq = $q->get( 'meta_query' ); if ( ! is_array( $mq ) ) { return; }
    $def = apply_filters( 'wpml_default_language', null );
    $walk = function ( $mq ) use ( &$walk, $def ) {
        foreach ( $mq as $i => $c ) {
            if ( ! is_array( $c ) ) { continue; }
            if ( ! isset( $c['key'] ) ) { $mq[ $i ] = $walk( $c ); continue; }
            if ( '_ywar_product_id' === $c['key'] && isset( $c['value'] ) && is_numeric( $c['value'] ) ) {
                $trid = apply_filters( 'wpml_element_trid', null, (int) $c['value'], 'post_product' );
                $ids = $trid ? array_values( array_map( 'intval', wp_list_pluck( (array) apply_filters( 'wpml_get_element_translations', null, $trid, 'post_product' ), 'element_id' ) ) ) : [];
                if ( $ids ) { $mq[ $i ]['value'] = $ids; $mq[ $i ]['compare'] = 'IN'; }
            } elseif ( in_array( $c['key'], [ 'ywar_review_box_product_ids', 'ywar_review_box_category_ids', 'ywar_review_box_tag_ids' ], true ) && preg_match( '/^:"(d+)";$/', (string) $c['value'], $m ) ) {
                $type = 'ywar_review_box_product_ids' === $c['key'] ? 'product' : ( 'ywar_review_box_category_ids' === $c['key'] ? 'product_cat' : 'product_tag' );
                $mq[ $i ]['value'] = ':"' . (int) apply_filters( 'wpml_object_id', (int) $m[1], $type, true, $def ) . '";';
            }
        }
        return $mq;
    };
    $q->set( 'meta_query', $walk( $mq ) );
} );

그러면 번역된 상품에 해당 상품의 모든 언어 버전에 대한 리뷰와 평점이 표시됩니다. 동일한 코드를 사용하면 상품, 카테고리 또는 태그에 설정된 리뷰 상자가 해당 번역에 적용됩니다.

모든 알려진 문제

이 문제에 대한 도움이 필요하십니까?

지원 문의를 하시면 저희가 함께 살펴보겠습니다.