WC_Order_Item_Meta::display( bool $flat = false, bool $return = false, string $hideprefix = '_', string $delimiter = ", n" )

Display meta in a formatted list.


Description Description


Parameters Parameters

$flat

(Optional) Flat (default: false).

Default value: false

$return

(Optional) Return (default: false).

Default value: false

$hideprefix

(Optional) Hide prefix (default: _).

Default value: '_'

$delimiter

(Optional) Delimiter used to separate items when $flat is true.

Default value: ", n"


Top ↑

Return Return

(string|void)


Top ↑

Source Source

File: includes/class-wc-order-item-meta.php

	public function display( $flat = false, $return = false, $hideprefix = '_', $delimiter = ", \n" ) {
		$output         = '';
		$formatted_meta = $this->get_formatted( $hideprefix );

		if ( ! empty( $formatted_meta ) ) {
			$meta_list = array();

			foreach ( $formatted_meta as $meta ) {
				if ( $flat ) {
					$meta_list[] = wp_kses_post( $meta['label'] . ': ' . $meta['value'] );
				} else {
					$meta_list[] = '
						<dt class="variation-' . sanitize_html_class( sanitize_text_field( $meta['key'] ) ) . '">' . wp_kses_post( $meta['label'] ) . ':</dt>
						<dd class="variation-' . sanitize_html_class( sanitize_text_field( $meta['key'] ) ) . '">' . wp_kses_post( wpautop( make_clickable( $meta['value'] ) ) ) . '</dd>
					';
				}
			}

			if ( ! empty( $meta_list ) ) {
				if ( $flat ) {
					$output .= implode( $delimiter, $meta_list );
				} else {
					$output .= '<dl class="variation">' . implode( '', $meta_list ) . '</dl>';
				}
			}
		}

		$output = apply_filters( 'woocommerce_order_items_meta_display', $output, $this, $flat );

		if ( $return ) {
			return $output;
		} else {
			echo $output; // WPCS: XSS ok.
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.