WC_Order_Item::get_formatted_meta_data() public WC 1.0
Expands things like term slugs before return.
{} Это метод класса: WC_Order_Item{}
Хуки из метода
Возвращает
Массив
. Ничего.
Использование
$WC_Order_Item = new WC_Order_Item(); $WC_Order_Item->get_formatted_meta_data( $hideprefix, $include_all );
- $hideprefix(строка)
- Meta data prefix, (default: _).
- $include_all(true|false)
- Include all meta data, this stop skip items with values already in the product name.
Код WC_Order_Item::get_formatted_meta_data() WC Order Item::get formatted meta data WC 5.2.2
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 );
}