WC_Emails::order_meta()publicWC 1.0

Add order meta to email templates.

Метод класса: WC_Emails{}

Возвращает

null. Ничего (null).

Использование

$WC_Emails = new WC_Emails();
$WC_Emails->order_meta( $order, $sent_to_admin, $plain_text );
$order(WC_Order) (обязательный)
Order instance.
$sent_to_admin(true|false)
If should sent to admin.
По умолчанию: false
$plain_text(true|false)
If is plain text email.
По умолчанию: false

Код WC_Emails::order_meta() WC 9.4.2

public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
	$fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );

	/**
	 * Deprecated woocommerce_email_order_meta_keys filter.
	 *
	 * @since 2.3.0
	 */
	$_fields = apply_filters( 'woocommerce_email_order_meta_keys', array(), $sent_to_admin );

	if ( $_fields ) {
		foreach ( $_fields as $key => $field ) {
			if ( is_numeric( $key ) ) {
				$key = $field;
			}

			$fields[ $key ] = array(
				'label' => wptexturize( $key ),
				'value' => wptexturize( $order->get_meta( $field ) ),
			);
		}
	}

	if ( $fields ) {

		if ( $plain_text ) {

			foreach ( $fields as $field ) {
				if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
					echo $field['label'] . ': ' . $field['value'] . "\n"; // WPCS: XSS ok.
				}
			}
		} else {

			foreach ( $fields as $field ) {
				if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
					echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>'; // WPCS: XSS ok.
				}
			}
		}
	}
}