WC_Order_Item::get_formatted_meta_data()
Expands things like term slugs before return.
Method of the class: WC_Order_Item{}
Hooks from the method
Return
Array
.
Usage
$WC_Order_Item = new WC_Order_Item(); $WC_Order_Item->get_formatted_meta_data( $hideprefix, $include_all );
- $hideprefix(string)
- Meta data prefix, .
Default: _) - $include_all(true|false)
- Include all meta data, this stop skip items with values already in the product name.
Default: false
WC_Order_Item::get_formatted_meta_data() WC Order Item::get formatted meta data code WC 7.7.0
public function get_formatted_meta_data( $hideprefix = '_', $include_all = false ) { $formatted_meta = array(); $meta_data = $this->get_meta_data(); $hideprefix_length = ! empty( $hideprefix ) ? strlen( $hideprefix ) : 0; $product = is_callable( array( $this, 'get_product' ) ) ? $this->get_product() : false; $order_item_name = $this->get_name(); foreach ( $meta_data as $meta ) { if ( empty( $meta->id ) || '' === $meta->value || ! is_scalar( $meta->value ) || ( $hideprefix_length && substr( $meta->key, 0, $hideprefix_length ) === $hideprefix ) ) { continue; } $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 ); if ( taxonomy_exists( $attribute_key ) ) { $term = get_term_by( 'slug', $meta->value, $attribute_key ); if ( ! is_wp_error( $term ) && is_object( $term ) && $term->name ) { $display_value = $term->name; } } // Skip items with values already in the product details area of the product name. if ( ! $include_all && $product && $product->is_type( 'variation' ) && wc_is_attribute_in_product_name( $display_value, $order_item_name ) ) { continue; } $formatted_meta[ $meta->id ] = (object) array( 'key' => $meta->key, 'value' => $meta->value, 'display_key' => apply_filters( 'woocommerce_order_item_display_meta_key', $display_key, $meta, $this ), 'display_value' => wpautop( make_clickable( apply_filters( 'woocommerce_order_item_display_meta_value', $display_value, $meta, $this ) ) ), ); } return apply_filters( 'woocommerce_order_item_get_formatted_meta_data', $formatted_meta, $this ); }