ภาพรวมของปัญหา
เมื่อใช้ Product Tabs for WooCommerce ร่วมกับ WPML คุณอาจพบปัญหาต่อไปนี้: เนื้อหาเฉพาะของผลิตภัณฑ์สำหรับแท็บไม่แสดงบนผลิตภัณฑ์ที่แปล ผลิตภัณฑ์ที่แปลจะแสดงเนื้อหาเริ่มต้นของแท็บแทน
วิธีแก้ปัญหาชั่วคราว
เพิ่มโค้ดต่อไปนี้ลงในไฟล์ functions.php ของธีมลูกของคุณ การทำเช่นนี้จะทำให้สินค้าที่แปลแสดงเนื้อหาแท็บของสินค้าต้นฉบับ
PHP
add_filter( 'get_post_metadata', function ( $value, $object_id, $meta_key, $single ) {
static $busy = false;
if ( $busy || ! is_string( $meta_key ) ) {
return $value;
}
foreach ( [ '_wpt_field_', '_wpt_override_' ] as $prefix ) {
if ( 0 !== strpos( $meta_key, $prefix ) ) {
continue;
}
$busy = true;
$own = get_post_meta( $object_id, $meta_key, true );
$out = $value;
if ( '' === $own ) {
$tab = get_page_by_path( substr( $meta_key, strlen( $prefix ) ), OBJECT, 'woo_product_tab' );
$orig = $tab ? (int) apply_filters( 'wpml_object_id', $tab->ID, 'woo_product_tab', false, apply_filters( 'wpml_default_language', null ) ) : 0;
if ( $orig && $orig !== (int) $tab->ID ) {
$v = get_post_meta( $object_id, $prefix . get_post_field( 'post_name', $orig ), true );
if ( '' !== $v ) {
$out = [ $v ];
}
}
}
$busy = false;
return $out;
}
return $value;
}, 10, 4 );อย่ากำหนด slug ของแท็บต้นฉบับให้กับแท็บที่แปลแทน เพราะจะทำให้เนื้อหาเริ่มต้นของแท็บแสดงเป็นภาษาต้นฉบับบนสินค้าที่แปลรายการอื่น ๆ