WC_Order_Item_Meta::get_formatted_legacy( string $hideprefix = '_' )
Return an array of formatted item meta in format e.g.
Description Description
Handles @deprecated args.
Parameters Parameters
- $hideprefix
-
(Optional) Hide prefix.
Default value: '_'
Return Return
(array)
Source Source
File: includes/class-wc-order-item-meta.php
public function get_formatted_legacy( $hideprefix = '_' ) {
if ( ! is_ajax() ) {
wc_deprecated_argument( 'WC_Order_Item_Meta::get_formatted', '2.4', 'Item Meta Data is being called with legacy arguments' );
}
$formatted_meta = array();
foreach ( $this->meta as $meta_key => $meta_values ) {
if ( empty( $meta_values ) || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) === $hideprefix ) ) {
continue;
}
foreach ( (array) $meta_values as $meta_value ) {
// Skip serialised meta.
if ( is_serialized( $meta_value ) ) {
continue;
}
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta_key ) );
// If this is a term slug, get the term's nice name.
if ( taxonomy_exists( $attribute_key ) ) {
$term = get_term_by( 'slug', $meta_value, $attribute_key );
if ( ! is_wp_error( $term ) && is_object( $term ) && $term->name ) {
$meta_value = $term->name;
}
}
// Unique key required.
$formatted_meta_key = $meta_key;
$loop = 0;
while ( isset( $formatted_meta[ $formatted_meta_key ] ) ) {
$loop ++;
$formatted_meta_key = $meta_key . '-' . $loop;
}
$formatted_meta[ $formatted_meta_key ] = array(
'key' => $meta_key,
'label' => wc_attribute_label( $attribute_key, $this->product ),
'value' => apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value, $this->meta, $this->item ),
);
}
}
return $formatted_meta;
}