0
votes

I have a product in woocommerce that is stored in chinese language,

The product has different color variations, woocommerce seems to encode the attribute taxonomy for the color attribute. in a english language product it would simple store the taxonomy as pa_color , but in my chinese language product, woocommerce store the taxonomy as pa_191386aef4bc441e , the letters and numbers after pa_ are an encoded form of the string 颜色 which translates to color in english, hence the term taxonomy pa_191386aef4bc441e simply means pa_color in english.

Am trying to figure out how woocommerce encoded the chinese string 颜色 to 191386aef4bc441e so that i can decode the text back to a valid chinese string, the final goal is to translate the product attributes to english and replace the chinese values with replaced english values.

How did woocommerce encode the product attribute so that i can decode it back to the original string ?

Look at at the picture below, the text pointed to by an arrow is the the chinese string that gets stored as pa_191386aef4bc441e enter image description here

Below is how the product data looks on the woocommerce database.

The post has an ID of 1347 enter image description here

terms

enter image description here

term relationships enter image description here

term taxonomy enter image description here

1

1 Answers

0
votes

I suffer from the same problem In another language (Hebrew) But I noticed that if you create the attribute in a programmatic way Does not have this problem As for example in this code

`<?php
require(dirname(__FILE__) . '/wp-load.php');

  //Create main product
$product = new WC_Product_Variable();

$att_var = array();
//Create the attribute object with name weight
$attribute = new WC_Product_Attribute();
$attribute->set_id( 0 );
$attribute->set_name( 'weight' );
$attribute->set_options( array(
        '50g',
        '100g',
        '150g'
) );
$attribute->set_position( 0 );
$attribute->set_visible( 1 );
$attribute->set_variation( 1 );
$att_var[] = $attribute;

//Create the attribute object with name brand
$attribute = new WC_Product_Attribute();
$attribute->set_name( 'חברה' );
$attribute->set_options( array(
        'מרצדס',
        'וולוו'
) );
$attribute->set_position( 1 );
$attribute->set_visible( 1 );
$attribute->set_variation( 1 );
$att_var[] = $attribute;

$product->set_attributes($att_var);
$product->set_name('Product 3');
$product->set_status('publish');
$product->set_sku(12345);

//Save main product to get its id
$product->set_category_ids([47, 56] );
$id = $product->save();

//variation 1
$variation = new WC_Product_Variation();
$variation->set_regular_price(10);
$variation->set_sale_price(10);
$variation->set_stock_quantity(12);
$variation->set_manage_stock(True);
$variation->set_weight('50g');
$variation->set_parent_id($id);

$variation->set_attributes(array(
        'weight' => '50g',
        'חברה' => 'מרצדס'
));

//Save variation, returns variation id
$variation->save();

//variation 2
$variation_new = new WC_Product_Variation();
$variation_new->set_regular_price(15);
$variation_new->set_sale_price(12);
$variation_new->set_stock_quantity(20);
$variation_new->set_manage_stock(True);
$variation_new->set_weight('100g');
$variation_new->set_parent_id($id);

//Set attributes requires a key/value containing
$variation_new->set_attributes(array(
        'weight' => '100g',
        'חברה' => 'וולוו'
));


//Save variation, returns variation id
$variation_new->save();`