1 回答
TA贡献1828条经验 获得超3个赞
要更改/更新产品属性分类数据,您需要使用wc_update_attribute()
function,因此在代码中更改产品属性标签名称:
$products = wc_get_products( array('category' => 't-shirts', 'orderby' => 'name') );
// Loop through queried products
foreach($products as $product) {
// Loop through product attributes
foreach( $product->get_attributes() as $attribute ) {
if( $attribute->is_taxonomy() ) {
$attribute_id = $attribute->get_id(); // Get attribute Id
$attribute_data = wc_get_attribute( $attribute_id ); // Get attribute data from the attribute Id
// Update the product attribute with a new taxonomy label name
wc_update_attribute( $attribute_id, array(
'name' => 'New label', // <== == == Here set the taxonomy label name
'slug' => $attribute_data->slug,
'type' => $attribute_data->type,
'order_by' => $attribute_data->order_by,
'has_archives' => $attribute_data->has_archives,
) );
}
}
}
经过测试并有效。
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报