I want wo add custom attribute for each product name in woocommerce order. Here is my code:
add_filter( 'woocommerce_order_get_items', 'filter_woocommerce_order_get_items', 10, 2 );
function filter_woocommerce_order_get_items($items, $instance){
foreach ($items as $item_id => $item){
$id = $item['product_id'];
$brand = array_shift( wc_get_product_terms( $id, 'pa_brand', array( 'fields' => 'names' ) ) );
if($brand) {
$items[$item_id]['name'] = $item['name'] . ' [' . $brand . ']';
}
}
return $items;
}
It looks normal for an old orders. But if it is a new order I've got such result:
Thanks for any advice!
question from:
https://stackoverflow.com/questions/65939017/filter-product-title-for-woocommerce-order-items 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…