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.

Sun Mon Tue Wed Thu Fri Sat
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -
- 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 19:00 – 22:00 -

Supporter timezone: Asia/Kathmandu (GMT+05:45)

This topic contains 6 replies, has 2 voices.

Last updated by Subash Chandra Poudel 1 year, 11 months ago.

Assisted by: Subash Chandra Poudel.

Author Posts
May 27, 2022 at 3:02 pm #11327967

Jean-Francois

I am trying to:

We have a client with ACF PRO. When he created his site, he put in the field name Files and File for file upload.

This was working before, but for a while it doesn't work anymore.

Have you changed anything in the code that might affect this?

We would like to find a solution without changing the 300 products and several attached files.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Like french site : hidden link

Instead, I got:

We spoke with ACF and he verified the code and told us that :

I am afraid this is a translation-related issue and from our end, we are not able to confirm how the WPML plugin handles translation therefore we are not in a better position to conclusively advise on this.

Due to the huge and complex changes in the WPML plugin, we may not be well equipped to advise on this translation-related issue. I would recommend reaching out to WPML support regarding the issue as their plugin is used in handling translation. Hopefully, they will shed some light on the same :).

Please note that our support is limited in scope to the basic usage of the ACF plugin and we don't offer any translation-related support to our customers.

Apologies for not being able to help and please let me know if there's anything else I can help you with.

functions to print :

function add_documents_product() {

$type = 'fichier';
$acf_document = 'documents';
$acf_file_name = 'nom';

if ( secrepro_get_current_lang() !== 'fr' ) {
$type = 'file';
$acf_document = 'files';
$acf_file_name = 'name';
}

$documents = get_field( $acf_document );

if ( empty( $documents ) || empty( $documents[0][ $type ] ) ) {
return;
}

$tpl = '<table class="swp_documents">';

foreach ( $documents as $document ) {
if ( empty( $document[ $type ] ) ) {
continue;
}

$tpl .= '<tr><td class="swp_nom_acf">' . $document[ $acf_file_name ] . '</td>';

$txt_btn_download = __( 'Télécharger', 'secrepro' );

$tpl .= <<<TPL
<td align="left" class="swp_td_btn">
<a href="{$document[$type]}" class="swp_btn_acf">{$txt_btn_download}</a>
</td>
</tr>
TPL;
}
$tpl .= '</table>';
echo wp_kses_post( $tpl );
}
add_action( 'woocommerce_before_add_to_cart_form', 'add_documents_product', 0, 10 );

I hope you can help us. Thanks.

May 30, 2022 at 2:44 pm #11345447

Subash Chandra Poudel

Hi there,

Thank you for contacting us, and apologies for the delayed response due to weekends and high queues.

Would you please elaborate more on what issue you are having with the ACF file/file upload field translation? I tried checking the links you shared, but it looks like it is password protected and requires a login to check.

Please share the site credentials for me to check the site. I have enabled the private reply for you to share the credentials safely.

Regards,
Subash

May 30, 2022 at 5:05 pm #11346457

Subash Chandra Poudel

Hi there,

Thank you for the details.

I can see the issue now. Please note that since the issue involves custom code, our support might be limited. However, I will try my best to help you.

You have translated the field group and have different names for the custom fields. I think the issue is coming from line 7 in the code you shared above. I see you have

...
if ( secrepro_get_current_lang() !== 'fr' ) {
...

But the function secrepro_get_current_lang is not appropriately defined in the code you shared. Please note the proper hook to use to get the current language with WPML is wpml_current_language, as explained in the next link:

https://wpml.org/wpml-hook/wpml_current_language/

Can you please recheck your code for secrepro_get_current_lang() function or adjust line 7 and see how it goes?

Regards,
Subash

May 30, 2022 at 5:46 pm #11346787

Jean-Francois

I don't believe this code is the cause of this problem. To demonstrate that this isn't the case, I edit the code to show you the result. We already this this idea before contact you.

Do you need anything else to debug this problem?

Desktop screenshot (21).png
Duo-Scan_ Go Plus (Copie) - SecRepro.png
May 31, 2022 at 12:40 pm #11353241

Subash Chandra Poudel

Hi there,

Thank you for the updates.

I edited your English Field group and set the internal name of the fields the same as in the french, and translated only the field labels. This seems to fix the issue now.

This should also simplify your code as multiple field names for multiple languages are now not required. I also edited your functions.php file and removed the if statement to change the field names based on the current language.

Since I noticed you are editing the translations manually/duplicating the pages, I have edited the field group and set all fields to not translate. You can change that if you want.

Please check it on the site and let me know how it goes for you.

Regards,
Subash

May 31, 2022 at 1:53 pm #11353993

Jean-Francois

Sorry, we know it works if we change the name of the field, we have already tested this. That's why we are contacting you. We have written this above:

This was working before, but for a while it doesn't work anymore.

Have you changed anything in the code that might affect this?

We would like to find a solution without changing the 300 products and several attached files.

Can you tell us how to change the name of all problematic fields related to the product and keep the value already entered?

Thanks

May 31, 2022 at 2:50 pm #11354659

Subash Chandra Poudel

Hi there,

Thank you for getting back with the details.

When you say: "This was working before, but for a while, it doesn't work anymore." do you mean when the field's name was set as files, file, and name for the English field group, it was working before?

- Have you changed anything in the code that might affect this?

No, I didn't change in the code anything related to this. I only changed the English field group field names to the same as french from the field group settings and removed the if('fr' !== $my_current_lang){... part in the code. But I have reverted it since this solution might not work for you if you have already entered the product data in the old field name.

- Can you tell us how to change the name of all problematic fields related to the product and keep the value already entered?

This can only be done using third-party plugins like WP All Export/Wp All Export. You can export the product data, including custom fields, and import them again to correct the field name. Please refer to the following documents for more details.

https://wpml.org/documentation/plugins-compatibility/export-multilingual-websites-using-wp-all-export-wpml/

https://wpml.org/documentation/related-projects/wpml-all-import-plugin-website-import-with-wpml/

It is logical to set the same field name for both translations and use only different field labels, which also solves the issue. But if you want to keep using different field names/identifiers, to troubleshoot the issue further and find if this is a WPML issue or not, I have created a sandbox site for you, which you can log in to using the following link:

hidden link

Please login to the site, set up WPML and your plugins, themes/code, and let me know. I will try my best to help you, but at some point, you might need to contact ACF support or work with a WPML contractor as this involves custom coding and ACF.

Regards,
Subash

The topic ‘[Closed] ACF PRO field name Files and File for file upload doesn't work anymore’ is closed to new replies.