Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 16 replies, has 2 voices.

Last updated by Andrey 1 year, 3 months ago.

Assisted by: Andrey.

Author Posts
October 10, 2023 at 8:59 am #14547683

irisH-8

I try to translate the products on our website. The products contain additional fields (created via PHP) and variations. The variations can only be translated via the WPML Translation Editor, but the extra fields are not listed here, so they cannot be translated. Is there any way the extra fields and variations can be translated?

If I translate the products through the front end, I can translate the extra fields but not the variations. In addition, the WPML Translate editor overwrites the translations done via the front end, leaving the extra fields empty in the different languages

hidden link

October 10, 2023 at 9:35 am #14548151

irisH-8

If we modify something in the variations, we need to translate it as well, the translated content from the extra fields disappears. Is there no other way to solve this? Because this is very cumbersome and takes a lot of time

October 10, 2023 at 3:26 pm #14551837

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for contacting WPML support.

It is expected that the translation is being overwritten. You must either translate using the WPML translation editor or the native editor.

Could you show me how you added those additional fields?

October 11, 2023 at 6:31 am #14555291

irisH-8

I add the additional fields via the "Modifier le produit". But through this option, I cannot translate the variations. How do I make sure I can translate all fields? So and the additional fields and the variations.

Scherm­afbeelding 2023-10-11 om 08.30.05.png
October 11, 2023 at 11:05 am #14558595

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Could you show me the process of adding the additional fields on the screenshots? The way you did this via the "Modifier le produit".

Did you add them in the original language of the product?

October 12, 2023 at 5:38 am #14562565

irisH-8

I add the text to the fields via Modifier le produit. The additional fields are made via PHP.

October 12, 2023 at 8:32 am #14563875

irisH-8

I added the additional field via PHP, so it is visible on all products

October 12, 2023 at 11:03 am #14565471

irisH-8

Is there an other supporter that can help? This is taking very long..

October 12, 2023 at 1:26 pm #14566429

irisH-8

Can someone help me solve this issue?

October 12, 2023 at 2:21 pm #14566817

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

I’m sorry that you ran into trouble with this. I’ll need a little more information to see what’s happening here. Could you share the PHP snippet of how you added them?

October 12, 2023 at 2:27 pm #14566835

irisH-8
///extra tabje
add_filter( 'woocommerce_product_tabs', 'ingredients_tab' );
function ingredients_tab( $tabs ) {
    $tabs['ingredients_tab'] = array(
        'title'     => __( 'Ingrediënten', 'woocommerce' ),
        'priority'  => 13,
        'callback'  => 'ingredients_tab_content'
    );
    return $tabs;
}

function ingredients_tab_content() {
    global $post;
    $current_language = apply_filters( 'wpml_current_language', NULL ); // Haal de huidige taal op
    $post_id = apply_filters( 'wpml_object_id', $post->ID, 'product', TRUE, $current_language ); // Haal de post-ID op voor de huidige taal

    $ingredients = get_post_meta( $post_id, '_ingredients', true );
    $ingredients_decoded = html_entity_decode($ingredients);
    echo apply_filters( 'the_content', $ingredients_decoded );
}




///extra html editor bij productpagina
add_action( 'add_meta_boxes', 'ingredients_meta_box' );
function ingredients_meta_box() {
    add_meta_box(
        'ingredients_meta_box',
        'Ingrediënten',
        'ingredients_meta_box_callback',
        'product',
        'normal',
        'high'
    );
}

function ingredients_meta_box_callback( $post ) {
    $ingredients = get_post_meta( $post->ID, '_ingredients', true );
    wp_editor( htmlspecialchars_decode( $ingredients ), '_ingredients', $settings = array('textarea_name'=>'_ingredients') );
}

add_action( 'save_post', 'save_ingredients_data' );
function save_ingredients_data( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return;
    if ( $parent_id = wp_is_post_revision( $post_id ) ) {
        $post_id = $parent_id;
    }
    $ingredients = isset( $_POST['_ingredients'] ) ? $_POST['_ingredients'] : '';
    update_post_meta( $post_id, '_ingredients', htmlspecialchars( $ingredients ) );
}

///extra tabje advies
add_filter( 'woocommerce_product_tabs', 'advies_tab' );
function advies_tab( $tabs ) {
    $tabs['advies_tab'] = array(
        'title'     => __( 'Advies', 'woocommerce' ),
        'priority'  => 14,
        'callback'  => 'advies_tab_content'
    );
    return $tabs;
}


function advies_tab_content() {
    global $post;
    $advies = get_post_meta( $post->ID, '_advies', true );
    $advies_decoded = html_entity_decode($advies);
    echo apply_filters( 'the_content', $advies_decoded );
}


///extra html editor als Advies bij productpagina
add_action( 'add_meta_boxes', 'advies_meta_box' );
function advies_meta_box() {
    add_meta_box(
        'advies_meta_box',
        'Advies',
        'advies_meta_box_callback',
        'product',
        'normal',
        'high'
    );
}

function advies_meta_box_callback( $post ) {
    $advies = get_post_meta( $post->ID, '_advies', true );
    wp_editor( htmlspecialchars_decode( $advies ), '_advies', $settings = array('textarea_name'=>'_advies') );
}

add_action( 'save_post', 'save_advies_data' );
function save_advies_data( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return;
    if ( $parent_id = wp_is_post_revision( $post_id ) ) {
        $post_id = $parent_id;
    }
    $advies = isset( $_POST['_advies'] ) ? $_POST['_advies'] : '';
    update_post_meta( $post_id, '_advies', htmlspecialchars( $advies ) );
}

///extra tabje Uw operatie
add_filter( 'woocommerce_product_tabs', 'uw_operatie_tab' );
function uw_operatie_tab( $tabs ) {
    global $post;
    $uw_operatie = get_post_meta( $post->ID, '_uw_operatie', true );
    if (!empty($uw_operatie)) {
        $tabs['uw_operatie_tab'] = array(
            'title'     => __( 'Uw operatie', 'woocommerce' ),
            'priority'  => 15,
            'callback'  => 'uw_operatie_tab_content'
        );
    }
    return $tabs;
}

function uw_operatie_tab_content() {
    global $post;
    $uw_operatie = get_post_meta( $post->ID, '_uw_operatie', true );
    $uw_operatie_decoded = html_entity_decode($uw_operatie);
    echo apply_filters( 'the_content', $uw_operatie_decoded );
}

///extra html editor als Uw operatie bij productpagina
add_action( 'add_meta_boxes', 'uw_operatie_meta_box' );
function uw_operatie_meta_box() {
    add_meta_box(
        'uw_operatie_meta_box',
        'Uw operatie',
        'uw_operatie_meta_box_callback',
        'product',
        'normal',
        'high'
    );
}

function uw_operatie_meta_box_callback( $post ) {
    $uw_operatie = get_post_meta( $post->ID, '_uw_operatie', true );
    wp_editor( htmlspecialchars_decode( $uw_operatie ), '_uw_operatie', $settings = array('textarea_name'=>'_uw_operatie') );
}

add_action( 'save_post', 'save_uw_operatie_data' );
function save_uw_operatie_data( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return;
    if ( $parent_id = wp_is_post_revision( $post_id ) ) {
        $post_id = $parent_id;
    }
    $uw_operatie = isset( $_POST['_uw_operatie'] ) ? $_POST['_uw_operatie'] : '';
    update_post_meta( $post_id, '_uw_operatie', htmlspecialchars( $uw_operatie ) );
}
October 12, 2023 at 7:23 pm #14568719

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for providing me with additional details. After reviewing the code you shared, I noticed that you are utilizing the post meta fields for the product. As a result, I believe that the custom fields _uw_operatie, _advies, and _ingredients can be made translatable in WPML → Setting → Custom field translation. Set them to Translate. Then, you should make a small modification to the original product, save it, and navigate to the WPML translation editor. The custom fields should now be visible in the editor.

If you need more information or assistance, please visit https://wpml.org/documentation/getting-started-guide/translating-custom-fields/.

October 13, 2023 at 7:58 am #14570535

irisH-8

Thank you for your response. It worked, thanks

October 13, 2023 at 8:23 am #14570749

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

That is strange. What if you go to WPML → Setting → Custom field translation and activate the option Show "Multilingual Content Setup" meta box on the post edit screen. Then, you should have the Custom fields meta box on the product editing screen. From there, you can locate the additional fields that the product contains. Maybe they have different names, but looking at your code, I listed the correct ones.

Edit-product-“Custom-Attributes”-‹-WCML-Plugin-GUI-—-WordPress.png
October 13, 2023 at 8:24 am #14570779

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Do not forget to click on "Show system fields".