Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing issues with ACF fields in a multilingual WooCommerce setup using WPML. Specifically, when updating a product in a secondary language, fields such as repeaters and relationship fields incorrectly inherit or duplicate content from the primary language product, despite being set to 'Copy once'.
Solution:
We recommend the following steps to address the issue:
1. Create a full backup of the site.
2. Navigate to

wp-content/plugins/sitepress-multilingual-cms/classes/custom-field-translation/class-wpml-copy-once-custom-field.php

and edit the

WPML_Copy_Once_Custom_Field::copy

method.
3. Replace the existing code with the following:

if ( ! get_post_meta( $post_id, 'copyoncedone' ) == 1 ) {<br />    add_post_meta($post_id, 'copyoncedone', 1 );<br />    foreach ( $custom_fields_to_copy as $meta_key ) {<br />        $values = isset( $custom_fields[ $meta_key ] ) ? $custom_fields[ $meta_key ] : [];<br />        if ( ! empty( $values ) ) {<br />            $values = array( $values );<br />        }<br />        $values = apply_filters(<br />            'wpml_custom_field_values',<br />            $values,<br />            [<br />                'post_id'                   => $post_id,<br />                'meta_key'                  => $meta_key,<br />                'custom_fields_translation' => WPML_COPY_ONCE_CUSTOM_FIELD,<br />            ]<br />        );<br /><br />        if ( empty ( $values ) && $source_element_id ) {<br />            $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );<br />        }<br />    }<br />}

4. Save the changes and verify if the issue is resolved.

If this solution does not apply to your case, or if it becomes outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

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 17 replies, has 2 voices.

Last updated by Carlos Rojas 1 year ago.

Assisted by: Carlos Rojas.

Author Posts
May 17, 2024 at 10:14 am

mortenS-12

ACF configuration

May 17, 2024 at 11:09 am
May 20, 2024 at 8:23 am #15644185

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi there,

I contacted my colleagues about this issue and they recommended starting by creating a staging site with a copy of the live site and then double-checking if the issue persists, also make sure the issue persists in a minimal setup (only WPML, ACF plugins, and a default WordPress theme).

Could you create a staging site with a copy of the live site?

Note: You can use this plugin to create the staging site for you: https://wordpress.org/plugins/wp-staging/

May 22, 2024 at 7:50 am #15654499

mortenS-12

Hi, we have tried using storefront, and minimal setup. Still same issue.

We have created a staging site, so you can check it out:

***

You can see the test product here:
hidden link
As you can see the repeater only return "1" if the repeater is not used on the danish version of the product.

so with the “translate” option it “works” if the danish product has a minimum of the same rows/repeaters in as on the english. If the english has content in a repeater the danish don’t have, the english version returns 1 instead of an array.

If we use copy once, we get the issue where if a repeater has 4 rows on the danish, but only 2 on the english, after changing any part of the english product we get row 3 and 4 from the danish product.

May 22, 2024 at 8:44 am #15656390

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Thank you for creating the staging site.

I changed the configuration of the ACF group and ran some troubleshooting steps. Please check if the issue persists with a new test product.

May 22, 2024 at 8:52 am #15656455

mortenS-12

It still persist, if you edit the product:
hidden link

You can see that there is nothing in the "Hvad Three columns" on the english version. On the danish version there is. If you update any part of the product, like the product description. It adds an empty row in the "Hvad Three columns" repeater.

May 22, 2024 at 9:04 am #15656520

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi there,

The URL you shared is from the same product in your previous message. If you create a new product, does the issue persist?

May 22, 2024 at 9:28 am #15656619

mortenS-12

Yes still persist, i created a new product:
hidden link

This has content in the "Hvad Second Row" on danish, but on the english version i have deleted the row, and updated. If you try to edit the product description (just add a letter or delete something), and update again, you can see that it adds an empty row in the "Hvad Second Row"

May 22, 2024 at 12:22 pm #15658088

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi,

I would like to ask for your authorization to create a copy of the site to escalate this issue to our 2nd tier of support where our 2nd tier specialists can take a deeper look at this problem, isolate its cause, and find a solution.

May 22, 2024 at 12:59 pm #15658433

mortenS-12

Hi,

Sounds good, you can go ahead and create a copy of the site 🙂

May 23, 2024 at 8:56 am #15661553

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi there,
Thank you for your authorization

I have created a copy of the site and escalated it to our 2nd tier of support. I will get back to you as soon as I get some information from our specialists in the 2nd tier.

May 24, 2024 at 6:16 am #15665666

mortenS-12

Thanks a lot 🙂

May 24, 2024 at 7:51 am #15665969

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

You are welcome 🙂

June 3, 2024 at 8:31 am #15696856

mortenS-12

Any updates? 🙂

June 3, 2024 at 10:22 am #15697346

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi there,

Not yet, I will keep you updated.