Home›Support›English Support›[Resolved] After saving a custom field data for woocommerce variable product i can't see the price and other t...
[Resolved] After saving a custom field data for woocommerce variable product i can't see the price and other t...
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.
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?
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.
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?
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.
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.
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
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.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.