WPML

Overview of the Issue

When using Product Tabs for WooCommerce with WPML, you might experience the following issue: a product’s own content for a tab does not show on the translated product. The translated product shows the tab’s default content instead.

Workaround

Add the following code to the functions.php file of your child theme. With it, a translated product shows the tab content of its original product.

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 );

Do not give the translated tab the slug of the original tab instead: then the tab’s default content shows in the original language on other translated products.

All known issues

Need Help with This Issue?

Ask a support question and we’ll look into it with you.