- Trạng thái
- Đã giải quyết
- Được báo cáo cho
- WPML Multilingual & Multicurrency for WooCommerce 4.0.1
- Đã giải quyết trong
- WooCommerce Multilingual 4.0.2
Tổng quan về lỗi
Vấn đề nằm ở việc một sản phẩm có các biến thể không hiển thị các biến thể bằng ngôn ngữ gốc. Các bản dịch của sản phẩm đó hiển thị tất cả các biến thể mà không gặp vấn đề gì.
Vui lòng lưu ý rằng vấn đề này chỉ xảy ra khi phân loại product_type được dịch. Phân loại này hoàn toàn không nên được dịch.
Ngôn ngữ gốc là ngôn ngữ mà ban đầu bạn đã tạo sản phẩm, và sau đó dịch nó từ ngôn ngữ đó sang các ngôn ngữ khác trên trang web của bạn.
Giải pháp tạm thời
Để khắc phục sự cố này, bạn cần thực hiện các bước sau:
- Thêm đoạn mã dưới đây vào tệp functions.php trong giao diện của bạn.
- Truy cập trang web của bạn trên giao diện người dùng và xác minh rằng sản phẩm hiện đã được hiển thị chính xác.
- Xóa đoạn mã khỏi tệp functions.php – nếu không làm như vậy có thể dẫn đến các vấn đề về hiệu suất.
function fix_product_type_terms(){
global $wpdb;
//check if terms were translated
$translations = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type'" );
if( $translations ){
foreach( $translations as $translation ){
if( !is_null( $translation->source_language_code ) ){
//check relationships
$term_relationships = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $translation->element_id ) );
if( $term_relationships ){
$orig_term = $wpdb->get_var( $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type' AND trid = %d AND source_language_code IS NULL", $translation->trid ) );
if( $orig_term ){
foreach( $term_relationships as $term_relationship ){
$wpdb->update(
$wpdb->term_relationships,
array(
'term_taxonomy_id' => $orig_term
),
array(
'object_id' => $term_relationship->object_id,
'term_taxonomy_id' => $translation->element_id
)
);
}
}
}
$term_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d", $translation->element_id ) );
if( $term_id ){
$wpdb->delete(
$wpdb->terms,
array(
'term_id' => $term_id
)
);
$wpdb->delete(
$wpdb->term_taxonomy,
array(
'term_taxonomy_id' => $translation->element_id
)
);
}
}
}
foreach( $translations as $translation ){
$wpdb->delete(
$wpdb->prefix . 'icl_translations',
array(
'translation_id' => $translation->translation_id
)
);
}
}
}
add_action( 'init' , 'fix_product_type_terms' );