Update uses of get_formatted_metadata to pass through filter first

This commit is contained in:
Thomas Roberts 2021-10-14 17:47:52 +01:00
parent bdf673c86d
commit 09450393d0
No known key found for this signature in database
GPG Key ID: 7C7EC4402EC08F35
5 changed files with 24 additions and 18 deletions

View File

@ -507,7 +507,10 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$html .= '<div class="wc-order-item-sku">' . esc_html( $product_object->get_sku() ) . '</div>';
}
$meta_data = $item->get_formatted_meta_data( '' );
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
$meta_data = $item->get_formatted_meta_data( '', $include_all );
if ( $meta_data ) {
$html .= '<table cellspacing="0" class="wc-order-item-meta">';

View File

@ -279,19 +279,8 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
}
}
$show_metadata_line = ! $include_all &&
$product && $product->is_type( 'variation' ) &&
wc_is_attribute_in_product_name( $display_value, $order_item_name );
$show_metadata_line = apply_filters(
'woocommerce_show_product_variant_metadata_line',
$attribute_key,
$display_value,
$product,
$show_metadata_line
);
// Skip items with values already in the product details area of the product name.
if ( ! $show_metadata_line ) {
if ( ! $include_all && $product && $product->is_type( 'variation' ) && wc_is_attribute_in_product_name( $display_value, $order_item_name ) ) {
continue;
}

View File

@ -213,7 +213,10 @@ class WC_API_Orders extends WC_API_Resource {
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_';
$item_meta = $item->get_formatted_meta_data( $hideprefix );
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
$item_meta = $item->get_formatted_meta_data( $hideprefix, $include_all );
foreach ( $item_meta as $key => $values ) {
$item_meta[ $key ]->label = $values->display_key;
@ -1525,7 +1528,10 @@ class WC_API_Orders extends WC_API_Resource {
foreach ( $refund->get_items( 'line_item' ) as $item_id => $item ) {
$product = $item->get_product();
$hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_';
$item_meta = $item->get_formatted_meta_data( $hideprefix );
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
$item_meta = $item->get_formatted_meta_data( $hideprefix, $include_all );
foreach ( $item_meta as $key => $values ) {
$item_meta[ $key ]->label = $values->display_key;

View File

@ -220,7 +220,10 @@ class WC_API_Orders extends WC_API_Resource {
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_';
$item_meta = $item->get_formatted_meta_data( $hideprefix );
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
$item_meta = $item->get_formatted_meta_data( $hideprefix, $include_all );
foreach ( $item_meta as $key => $values ) {
$item_meta[ $key ]->label = $values->display_key;
@ -1570,7 +1573,10 @@ class WC_API_Orders extends WC_API_Resource {
foreach ( $refund->get_items( 'line_item' ) as $item_id => $item ) {
$product = $item->get_product();
$hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_';
$item_meta = $item->get_formatted_meta_data( $hideprefix );
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
$item_meta = $item->get_formatted_meta_data( $hideprefix, $include_all );
foreach ( $item_meta as $key => $values ) {
$item_meta[ $key ]->label = $values->display_key;

View File

@ -3336,7 +3336,9 @@ if ( ! function_exists( 'wc_display_item_meta' ) ) {
)
);
foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
$include_all = false;
$include_all = apply_filters( 'woocommerce_get_formatted_meta_data_include_all_meta_lines', $include_all, $item );
foreach ( $item->get_formatted_meta_data( '_', $include_all ) as $meta_id => $meta ) {
$value = $args['autop'] ? wp_kses_post( $meta->display_value ) : wp_kses_post( make_clickable( trim( $meta->display_value ) ) );
$strings[] = $args['label_before'] . wp_kses_post( $meta->display_key ) . $args['label_after'] . $value;
}