WC_Order_Item::get_formatted_meta_data()publicWC 1.0

Expands things like term slugs before return.

Method of the class: WC_Order_Item{}

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() code WC 8.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 );
}