Skip Navigation

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

Problem:
The client is attempting to save custom field data for a WooCommerce variable product using the WPML plugin. They have added custom price fields but encounter an issue where the product page reloads and displays nothing after saving the variable custom field data.
Solution:
We clarified that the 'wcml_product_custom_prices' filter is intended for currency conversion, not for language translation or updating postmeta on translated products. To handle custom fields correctly across different languages, the client should ensure that they are using the WPML object ID filter to get the correct product ID for each language. This approach helps in storing custom field values separately for each language. If the client is not planning to use different prices per language but wants to enable translation of the custom field, they should:
1. Add the custom field for each product (_purchase_cost).
2. Enable the translation of that custom field per language via WPML.
3. Store the custom field values separately for each language, ensuring that the values are saved correctly when the product is edited in different languages.
For further assistance, we 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 at https://wpml.org/forums/forum/english-support/.

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.

Tagged: 

This topic contains 5 replies, has 0 voices.

Last updated by Andreas W. 1 month, 1 week ago.

Assisted by: Andreas W..

Author Posts
April 30, 2025 at 6:44 am #16981776

marioG-45

Background of the issue:
I am trying to save custom field data for a WooCommerce variable product using the WPML plugin. I have added custom price fields using the following code:

add_filter( 'wcml_custom_prices_fields', 'add_custom_price_fields', 10, 2 );
function add_custom_price_fields( $fields, $product_id ) {
// Add a new custom price field
$fields[] = '_purchase_cost';
return $fields;
}
add_filter( 'wcml_custom_prices_fields_labels', 'set_labels_for_price_fields', 10, 2 );
function set_labels_for_price_fields( $labels, $product_id ){
// Edit the label of a custom price field
$labels[ '_purchase_cost' ] = __( 'Purchase cost', 'woocommerce-multilingual' );
return $labels;
}
add_filter( 'wcml_update_custom_prices_values', 'add_purchase_cost_to_custom_prices', 10, 3 );
function add_purchase_cost_to_custom_prices( $custom_prices, $code, $post_id ) {
$purchase_cost = get_post_meta( $post_id, '_purchase_cost'.'_' . $code, true );
if (isset($_POST["_custom_purchase_cost"][$code])){
$purchase_cost = $_POST["_custom_purchase_cost"][$code];
}
$custom_prices['_purchase_cost'] = $purchase_cost;
return $custom_prices;
}

Screenshot: hidden link

Symptoms:
After saving the variable custom field data, the product page reloads, and I can't see anything. When I comment out the code, things work fine, but I can't see the custom field.

Questions:
Why does the product page reload and not display anything after saving the variable custom field data?
How can I save custom field data for a WooCommerce variable product without causing the page to reload incorrectly?

May 3, 2025 at 2:54 am #16991320

Andreas W.
WPML Supporter since 12/2018

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

Timezone: America/Lima (GMT-05:00)

Hello,

'wcml_product_custom_prices'
This filter is for currency conversion, not language translation. It's used when WCML calculates prices for other currencies (like USD, EUR).

Are you trying to set different prices for different currencies or do you simply want to update postmeta on a translated product?

When using the $poduct_id you need to make sure to check for the current language and use the WPML object ID filer, as each post, page, or product has a different ID in each language.

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

Could you please clarify what you are trying to achieve?

From what I understand you want to:

- Add a custom field for each product (_purchase_cost).

- Enable the translation of that custom field per language via WPML.

- Store the custom field values separately for each language, ensuring that the values are saved correctly when the product is edited in different languages.

Are you planning to use different prices per language?

Best regards
Andreas

May 5, 2025 at 4:54 am #16994215

marioG-45

Hi Andreas,

For now I'm not thinking to use different prices per different languages.
Actually I had just added one custom field in name called "Purchase cost". You can see that in my previous message.

So that custom field is working with simple type wocoomerce product. Its appearing in variable product as well for each variation. But when I save that custom field in variation product then its not storing the custom field data.

You can see my whole code in previous comment so you can test it your testing environment as well.

Please review this ticket as well so you can get better idea.
Ticket link :- https://wpml.org/forums/topic/need-help-for-wpml-multi-currency

Could you please check that and let me know.
Thanks

May 6, 2025 at 11:45 pm #17003901

Andreas W.
WPML Supporter since 12/2018

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

Timezone: America/Lima (GMT-05:00)

My apologies but I am not sure what you are trying to achieve.

The WCML Custom Price Hooks will only change the value for different prices in different currencies, not for the product price in WooCommerce, and works on a multi-currency base.

These hooks can only be used for these fields:

_regular_price

_sale_price

_sale_price_dates_from

_sale_price_dates_to

_wcml_schedule

Those hooks can not be used for your own custom fields.

I can offer a WPML test site on which you can recreate the issue and I take a closer look.

May 7, 2025 at 8:47 am #17005139

marioG-45

Hello Andreas,
Okay please share your test site so I'll show show you what I'm exactly talking about.
Also add the woocommerce inside the test site.

Also did you review this below ticket to understand which of the things I'm asking for. Your support team member Dražen is also checking on it. So please check with him if possible.
Ticket link :- https://wpml.org/forums/topic/need-help-for-wpml-multi-currency

Thanks

May 7, 2025 at 3:41 pm #17007617

Andreas W.
WPML Supporter since 12/2018

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

Timezone: America/Lima (GMT-05:00)

It looks like we are handling the same issue with duplicated tickets.

Confirm, please.

If our ticket is a duplicate and the issue has already escalated, then I would kindly like to ask you to close this ticket.