WPML
สถานะ
แก้ไขแล้ว
รายงานสำหรับ
WPML Multilingual CMS 4.6.13
แก้ไขใน
WPML Multilingual CMS 4.7.4
ปลั๊กอิน/ธีมที่เกี่ยวข้อง
Elementor
แท็กหัวข้อ
Compatibility

ภาพรวมของปัญหา

เมื่อใช้ฟีเจอร์ Display Conditions ของ Elementor Pro เพื่อควบคุมการแสดงผลของวิดเจ็ต เงื่อนไขจะไม่ทำงานอย่างถูกต้องในหน้าที่แปล โดยเฉพาะอย่างยิ่ง แท็ก หรือ หมวดหมู่ ในภาษาที่แปลจะไม่ทำให้เงื่อนไขการแสดงผลทำงานตามที่คาดไว้ ทำให้องค์ประกอบที่ควรถูกซ่อนยังคงมองเห็นได้

วิธีแก้ปัญหาชั่วคราว

โปรดตรวจสอบให้แน่ใจว่าคุณได้สำรองข้อมูลไซต์ทั้งหมดก่อนดำเนินการต่อ


  • เปิดไฟล์ functions.php ของธีมของคุณ

  • เพิ่มโค้ดต่อไปนี้:
    /*
    * WPML Workaround for compsupp-7656
    */
    add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7656_filter_e_display_conditions_from_widget');
    
    function wpml_compsupp7656_filter_e_display_conditions_from_widget($element) {
        $settings = $element->get_settings();
    
        if (array_key_exists('e_display_conditions', $settings) && !empty($settings['e_display_conditions'])) {
            foreach ($settings['e_display_conditions'] as $key => $condition_json) {
                $condition = json_decode($condition_json, true);
                
                foreach ($condition as &$condition_group) {
                    foreach ($condition_group as &$single_condition) {    
                        if (isset($single_condition['condition']) && strpos($single_condition['condition'], 'in_') === 0) {
                            $taxonomy_key = substr($single_condition['condition'], 3); // Remove 'in_' prefix
                            if (isset($single_condition[$taxonomy_key])) {
                                foreach ($single_condition[$taxonomy_key] as &$term) {
                                    if (isset($term['id'])) {
                                        $term_obj = get_term($term['id']);
                                        if ($term_obj && !is_wp_error($term_obj)) {
                                            $term['id'] = apply_filters('wpml_object_id', $term['id'], $term_obj->taxonomy, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
    
                // Encode the modified condition back to JSON
                $settings['e_display_conditions'][$key] = json_encode($condition);
            }
    
            // Update the element's settings with the modified conditions
            $element->set_settings('e_display_conditions', $settings['e_display_conditions']);
        }
    }

ปัญหาที่ทราบแล้วทั้งหมด →