This thread is resolved. Here is a description of the problem and solution.
Problem:
You are working on a site under development and trying to add an extra field using
wcml_custom_prices_fields
. The field appears properly, but after saving, its value does not appear.
Solution:
We recommend adjusting your code as follows:
add_filter( 'wcml_custom_prices_fields', 'add_custom_price_fields', 10, 2 );<br />function add_custom_price_fields( $fields, $product_id ) {<br />// Add a new custom price field<br />$fields[] = '_purchase_cost';<br />return $fields;<br />}<br /><br />add_filter( 'wcml_custom_prices_strings', 'set_labels_for_price_fields', 10, 2 );<br /><br />add_filter( 'wcml_custom_prices_fields_labels', 'set_labels_for_price_fields', 10, 2 );<br />function set_labels_for_price_fields( $labels, $product_id ){<br />// Edit the label of a custom price field<br />$labels[ '_purchase_cost' ] = __( 'Purchase cost', 'woocommerce-multilingual' );<br />return $labels;<br />}<br /><br />add_filter( 'wcml_update_custom_prices_values', 'add_purchase_cost_to_custom_prices', 10, 3 );<br />function add_purchase_cost_to_custom_prices( $custom_prices, $code, $post_id ) {<br /> $type = get_post_type($post_id);<br /> if ( 'product' == $type ) {<br /> $purchase_cost = get_post_meta($post_id, '_purchase_cost' . '_' . $code, true);<br /> if (isset($_POST["_custom_purchase_cost"][$code])) {<br /> $purchase_cost = $_POST["_custom_purchase_cost"][$code];<br /> }<br /> } elseif ( 'product_variation' == $type ) {<br /> $purchase_cost = get_post_meta($post_id, '_purchase_cost' . '_' . $code, true);<br /> if (isset($_POST["_custom_variation_purchase_cost"][$code])) {<br /> $purchase_cost = $_POST["_custom_variation_purchase_cost"][$code][$post_id];<br /> }<br /> }<br />$custom_prices['_purchase_cost'] = $purchase_cost;<br />return $custom_prices;<br />}
If this solution does not resolve your issue or seems outdated, please check the related known issues and verify that you have installed the latest versions of themes and plugins. If the problem persists, we highly recommend opening a new support ticket at WPML support forum.
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 22 replies, has 0 voices.
Last updated by 2 months, 2 weeks ago.
Assisted by: Dražen.