Automattic\WooCommerce\Internal\PushNotifications\Notifications

NewOrderNotification::to_payloadpublicWC 10.7.0

Returns the WPCOM-ready payload for this notification.

Returns null if the order no longer exists.

Method of the class: NewOrderNotification{}

No Hooks.

Returns

Array|null.

Usage

$NewOrderNotification = new NewOrderNotification();
$NewOrderNotification->to_payload(): ?array;

Changelog

Since 10.7.0 Introduced.

NewOrderNotification::to_payload() code WC 10.8.1

public function to_payload(): ?array {
	$order = WC()->call_function( 'wc_get_order', $this->get_resource_id() );

	if ( ! $order || ! $order instanceof WC_Order ) {
		return null;
	}

	return array(
		'type'        => $this->get_type(),
		'icon'        => self::ICON,
		// This represents the time the notification was triggered, so we can monitor age of notification at delivery.
		'timestamp'   => gmdate( 'c' ),
		'resource_id' => $this->get_resource_id(),
		'title'       => array(
			/**
			 * This will be translated in WordPress.com, format:
			 * 1: emoji
			 */
			'format' => 'You have a new order! %1$s',
			'args'   => array( self::EMOJI_LIST[ wp_rand( 0, count( self::EMOJI_LIST ) - 1 ) ] ),
		),
		'message'     => array(
			/**
			 * This will be translated in WordPress.com, format:
			 * 1: order total, 2: site title
			 */
			'format' => 'New order for %1$s on %2$s',
			'args'   => array(
				wp_strip_all_tags( $order->get_formatted_order_total() ),
				wp_strip_all_tags( get_bloginfo( 'name' ) ),
			),
		),
		'meta'        => array(
			'order_id' => $this->get_resource_id(),
		),
	);
}