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 thread is resolved. Here is a description of the problem and solution.

Problem: I have created custom fields that do not show up in WPML -> Settings. How can I set them to copy?

Solution: You can set the fields to copy in a wpml-config.xml file. You can follow the steps here: https://wpml.org/documentation/support/language-configuration-files/#custom-fields

This topic contains 2 replies, has 2 voices.

Last updated by stijnv-8 1 year ago.

Assigned support staff: Lauren.

Author Posts
September 28, 2018 at 11:39 pm #2774930

stijnv-8

Hello,

I have two custom fields in my product variations that I would like to be able to have copied automatically from the default language to the other language(s) upon saving the product.

The two fields are working fine on their own.

The fields are not visible under Multilingual Content Setup.

PS: the code I used to generate the two fields:

<?php

/*
Plugin Name: Add variation data per product
Plugin URL: hidden link
Description: Adds a "recently viewed products" shortcode
Version: 1.0
Author: Stijn van der Pol
Author URI: hidden link
Contributors: corsonr
Text Domain: rc_wc_rvp
Domain Path: languages
*/

// 1. Add custom field input @ Product Data > Variations > Single Variation

add_action( 'woocommerce_variation_options_pricing', 'variation_settings_fieldswc', 10, 3 );

function variation_settings_fieldswc( $loop, $variation_data, $variation ) {
// Text Field
woocommerce_wp_text_input(
array(
'id' => '_artist_win_var[' . $variation->ID . ']',
'label' => __( 'Artist Win Var', 'woocommerce' ),
'placeholder' => '0',
'desc_tip' => 'true',
'description' => __( 'The amount in euros that friendmade pays to the Artist.', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_artist_win_var', true )
)
);

// Text Field
woocommerce_wp_text_input(
array(
'id' => '_print_file_URL[' . $variation->ID . ']',
'label' => __( 'Print File URL', 'woocommerce' ),
'placeholder' => '0',
'desc_tip' => 'true',
'description' => __( 'The link for production to find print file incl hidden link... ', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_print_file_URL', true )
)
);

}

// -----------------------------------------
// 2. Save custom field on product variation save

add_action( 'woocommerce_save_product_variation', 'variation_settings_fieldswc_save', 10, 2 );

function variation_settings_fieldswc_save( $variation_id, $i ) {
$custom_field = $_POST['_artist_win_var'][$i];
if ( ! empty( $custom_field ) ) {
update_post_meta( $variation_id, '_artist_win_var', esc_attr( $custom_field ) );
} else delete_post_meta( $variation_id, '_artist_win_var' );

$custom_field2 = $_POST['_print_file_URL'][$i];
if ( ! empty( $custom_field2 ) ) {
update_post_meta( $variation_id, '_print_file_URL', esc_attr( $custom_field2 ) );
} else delete_post_meta( $variation_id, '_artist_win_var' );

}

// -----------------------------------------
// 3. Store custom field value into variation data

add_filter( 'woocommerce_available_variation', 'bbloomer_add_custom_field_variation_data' );

function bbloomer_add_custom_field_variation_data( $variations ) {
$variations['_artist_win_var'] = '<div class="woocommerce_custom_field">Custom Field: <span>' . get_post_meta( $variations[ 'variation_id' ], '_artist_win_var', true ) . '</span></div>';
return $variations;

$variations2['_print_file_URL'] = '<div class="woocommerce_custom_field">Custom Field: <span>' . get_post_meta( $variations2[ 'variation_id' ], '_print_file_URL', true ) . '</span></div>';
return $variations2;
}

?>

October 1, 2018 at 4:47 pm #2778878

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thank you for contacting WPML support. I'll be happy to help you with this.

You can try setting the fields to copy in a wpml-config.xml file. You can follow the steps here: https://wpml.org/documentation/support/language-configuration-files/#custom-fields

Please let me know if you need any further assistance and I will be happy to help.

October 1, 2018 at 7:05 pm #2779236

stijnv-8

Thanks Lauren! Sorry I missed that one. Great to know!