ภาพรวมของปัญหา
เมื่อใช้ปลั๊กอิน YITH WooCommerce Advanced Reviews ร่วมกับ WPML สินค้าที่แปลแล้วจะไม่แสดงรีวิวใด ๆ ของสินค้าต้นฉบับ แท็บรีวิวจะแสดง 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 ) ); } );
จากนั้นสินค้าที่แปลจะแสดงรีวิวและคะแนนของสินค้าในทุกเวอร์ชันภาษา โค้ดเดียวกันนี้จะทำให้กล่องรีวิวที่ตั้งค่าไว้สำหรับสินค้า หมวดหมู่ หรือแท็ก มีผลกับการแปลของรายการเหล่านั้นด้วย