更新:
functions.php 中的这些过滤器对我有用:
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_true' );
add_filter( 'woocommerce_is_attribute_in_product_name', '__return_true' );
我试图在 WooCommerce REST API 的“名称”键中包含所选变体的名称。产品只有一个属性 - 在此示例中,颜色将显示在标题中并在 API 中正确显示:
"id": 26293,
"name": "Signia Pure Charge & Go 5Nx - Silver",
"product_id": 156899,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "1767.67",
"subtotal_tax": "159.09",
"total": "1767.67",
"total_tax": "159.09",
"taxes": [
{
"id": 32,
"total": "159.090275",
"subtotal": "159.090275"
}
但是 - 如果产品有多种变体,在下面的示例中,颜色和左或右选项不会在产品标题中指定。
当产品有多个变体时,是否可以将变体值分配给标题?
"line_items": [
{
"id": 26325,
"name": "Signia Silk 7Nx",
"product_id": 25860,
"variation_id": 56082,
"quantity": 1,
"tax_class": "",
"subtotal": "1283.49",
"subtotal_tax": "115.51",
"total": "1283.49",
"total_tax": "115.51",
"taxes": [
{
"id": 1,
"total": "115.513761",
"subtotal": "115.513761"
}
],
"meta_data": [
{
"id": 191467,
"key": "links-en-of-rechts",
"value": "Rechts",
"display_key": "Links en\/of rechts",
"display_value": "Rechts"
},
{
"id": 191468,
"key": "pa_kleur",
"value": "black",
"display_key": "Kleur",
"display_value": "Black"
}