Woocommerce中国产品属性分类的特殊编码

问题描述

我有一个用中文存储的woocommerce产品,

该产品具有不同的颜色变化,woocommerce似乎encode是颜色属性的属性分类法。在英语产品中,将分类法简单地存储为pa_color,而在我的中文产品中,woocommerce将分类法存储为pa_191386aef4bc441epa_之后的字母和数字是{{字符串encoded form的1}}转换为英语的颜色,因此术语分类法颜色在英语中仅表示pa_191386aef4bc441e

我试图弄清楚woocommerce如何将中文字符串pa_color编码为颜色,以便我可以将文本解码回有效的中文字符串,最终目标是将产品属性翻译成英文并用替换后的英语值替换中文值。

woocommerce如何编码产品属性,以便我可以将其解码回原始字符串?

看下面的图片,箭头指向的文本是中文字符串,它存储为191386aef4bc441e

enter image description here

下面是产品数据在woocommerce数据库上的外观。

帖子的ID为pa_191386aef4bc441e

enter image description here

条款

enter image description here

长期关系

enter image description here

术语分类

enter image description here

解决方法

我也遇到同样的问题 用另一种语言(希伯来语) 但是我注意到,如果您以编程方式创建属性 没有这个问题 例如在这段代码中

`<?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();`

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...