- 상태
- 해결됨
- 보고된 제품
- 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' );