- สถานะ
- แก้ไขแล้ว
- รายงานสำหรับ
- WPML Multilingual & Multicurrency for WooCommerce 4.0.1
- แก้ไขใน
- WooCommerce Multilingual 4.0.2
ภาพรวมของปัญหา
ปัญหาคือสินค้าที่มีรูปแบบย่อยไม่แสดงรูปแบบย่อยในภาษาต้นฉบับ ฉบับแปลของสินค้านั้นสามารถแสดงรูปแบบย่อยทั้งหมดได้โดยไม่มีปัญหา
โปรดทราบว่าปัญหานี้จะเกิดขึ้นก็ต่อเมื่ออนุกรมวิธาน product_type ถูกแปลเท่านั้น อนุกรมวิธานนี้ไม่ควรถูกแปลเลย
ภาษาต้นฉบับคือภาษาที่คุณใช้สร้างสินค้าในตอนแรก จากนั้นจึงแปลจากภาษานั้นเป็นภาษาอื่น ๆ บนเว็บไซต์ของคุณ
วิธีแก้ปัญหาชั่วคราว
เพื่อแก้ไขปัญหานี้ คุณต้องทำตามขั้นตอนต่อไปนี้:
- เพิ่มโค้ดด้านล่างนี้ลงในไฟล์ functions.php ของธีมของคุณ
- เข้าไปที่ส่วนหน้าเว็บไซต์ของคุณและตรวจสอบว่าสินค้าแสดงผลอย่างถูกต้องแล้ว
- ลบโค้ดออกจากไฟล์ functions.php – หากไม่ทำเช่นนั้นอาจส่งผลให้เกิดปัญหาด้านประสิทธิภาพ
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' );