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 關注
- 167 瀏覽
添加回答
舉報