• Resolved mbgrafik

    (@marcobecker)


    Hi dear WCMLTeam,

    i hope you can lead me in the right direction:

    $feat =   get_post_meta( $values[ 'product_id' ], 'features', true );
    wc_add_order_item_meta( $item_id, 'Features',  $feat , false );

    gives me in both languages:

    Features
    Here are the features

    How to: get the translated ‘Features’ and the related data on order view/Email again again as i need:

    Features(EN)
    Here are the features…
    Eigenschaften(DE)
    das sind die…

Viewing 4 replies - 1 through 4 (of 4 total)
  • As far as I understand you have a feature meta in the product, and that is not being displayed properly for you.
    Did you try to use WPML api to get the translated value? – https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
    Maybe getting the translated product may help – something like:

            $order_language = get_post_meta( $order->id, 'wpml_language', true );
    
            $tr_product_id = apply_filters( 'translate_object_id', $product_id, get_post_type( $product_id ), false, $order_language );

    I am afraid that without more information, I cannot be of better help.

    If you wish, you can always create a new ticket in our forum at wpml.org so that we can help you better and try and debug your setup.

    Thread Starter mbgrafik

    (@marcobecker)

    Hi George, thx for your reply ??

    // add extra info to general product tab
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    // Text Field
    woocommerce_wp_textarea_input(
    array(
    'id' => 'features',
    'label' => __( 'Features', 'woocommerce' ),
    'placeholder' => 'add features here',
    'desc_tip' => 'true',
    'description' => __( 'You can add features information in this field', 'woocommerce' )
    )
    );
    }
    //save post meta data
    function woo_add_custom_general_fields_save( $post_id ){
    	$feat = $_POST['features'];
    	// if set  > save data to post_meta
    	if( isset( $feat ) )
    	update_post_meta( $post_id, 'Features', esc_attr( $feat ) );
    	// if set  > save data to post_meta
    }

    When i view the order in my account page and switch languages the product title translates

    Productname (EN)
    Features <-
    text (ok)

    now switch language to DE
    Produktname(DE)
    Features <- this should become Eigenschaften
    text (ok)

    • This reply was modified 8 years, 4 months ago by mbgrafik.
    Thread Starter mbgrafik

    (@marcobecker)

    missed some part of the code, sorry, so here is the full

    // add extra info to general product tab
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    // Text Field
    woocommerce_wp_textarea_input(
    array(
    'id' => 'features',
    'label' => __( 'Features', 'woocommerce' ),
    'placeholder' => 'add features here',
    'desc_tip' => 'true',
    'description' => __( 'You can add features information in this field', 'woocommerce' )
    )
    );
    }
    //save post meta data
    function woo_add_custom_general_fields_save( $post_id ){
    	$feat = $_POST['features'];
    	// if set  > save data to post_meta
    	if( isset( $feat ) )
    	update_post_meta( $post_id, 'features', esc_attr( $feat ) );
    }
    // add to order
    add_action( 'woocommerce_add_order_item_meta', 'woo_order_extra_meta', 10, 3 );
    function woo_order_extra_meta( $item_id, $values, $cart_item_key ) {
    $feat =   get_post_meta( $values[ 'product_id' ], 'features', true );
    wc_add_order_item_meta( $item_id, 'Features',  $feat , false );

    iF I understand your setup correctly, you have a static string for the “Features”.
    Perhaps you can also use our api for that string as well:
    https://wpml.org/wpml-hook/wpml_register_single_string/
    do_action( 'wpml_register_single_string', string $context, string $name, string $value )
    – to register the string and then you can translate it in WPML > String Translation (you can include this near the place where you want to show the value, or in separate file – it does not matter).
    https://wpml.org/wpml-hook/wpml_translate_single_string/
    apply_filters( 'wpml_translate_single_string', string $original_value, string $domain, string $name, string $language_code )
    – to translate it -> you call this at the place where you want to display the value

    You can see sample code on how to use it in the urls that I have provided.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘translation problem order_item_meta’ is closed to new replies.