Filter out product variation line_item meta
There are cases where we want to display line item meta, similar to the
checkout flow on the web. The web filters out variation meta because
it's redundant. The product name already includes the relevant meta.
ref: 8bc310008c/plugins/woocommerce/includes/class-wc-order-item.php (L282-L285)
This commit is contained in:
parent
11fa76e447
commit
e35c7ac6dc
|
@ -210,6 +210,27 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
|
|||
|
||||
// Expand meta_data to include user-friendly values.
|
||||
$formatted_meta_data = $item->get_formatted_meta_data( null, true );
|
||||
|
||||
// Filter out product variations
|
||||
// TODO: Add a query arg to activate this. Default should be to keep variation meta for back-compat
|
||||
if ( $product ) {
|
||||
$order_item_name = $data['name'];
|
||||
$data['meta_data'] = array_filter( $data['meta_data'], function( $meta ) use ( $product, $order_item_name ) {
|
||||
$meta->key = rawurldecode( (string) $meta->key );
|
||||
$meta->value = rawurldecode( (string) $meta->value );
|
||||
$attribute_key = str_replace( 'attribute_', '', $meta->key );
|
||||
$display_key = wc_attribute_label( $attribute_key, $product );
|
||||
$display_value = wp_kses_post( $meta->value );
|
||||
|
||||
// Skip items with values already in the product details area of the product name.
|
||||
if ( $product && $product->is_type( 'variation' ) && wc_is_attribute_in_product_name( $display_value, $order_item_name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} );
|
||||
}
|
||||
|
||||
$data['meta_data'] = array_map(
|
||||
array( $this, 'merge_meta_item_with_formatted_meta_display_attributes' ),
|
||||
$data['meta_data'],
|
||||
|
|
Loading…
Reference in New Issue