Automattic\WooCommerce\Internal\PushNotifications\Triggers

NewOrderNotificationTrigger::on_order_status_changedpublicWC 10.7.0

Handles the woocommerce_order_status_changed hook.

Method of the class: NewOrderNotificationTrigger{}

No Hooks.

Returns

null. Nothing (null).

Usage

$NewOrderNotificationTrigger = new NewOrderNotificationTrigger();
$NewOrderNotificationTrigger->on_order_status_changed( $order_id, $previous_status, $next_status, $order ): void;
$order_id(int) (required)
The order ID.
$previous_status(string) (required)
The previous order status.
$next_status(string) (required)
The new order status.
$order(WC_Order) (required)
The order object.

Changelog

Since 10.7.0 Introduced.

NewOrderNotificationTrigger::on_order_status_changed() code WC 10.8.1

public function on_order_status_changed(
	int $order_id,
	string $previous_status,
	string $next_status,
	WC_Order $order
): void {
	// phpcs:enable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
	if (
		in_array( $previous_status, self::NOTIFIABLE_STATUSES, true )
		|| ! in_array( $next_status, self::NOTIFIABLE_STATUSES, true )
	) {
		return;
	}

	wc_get_container()->get( PendingNotificationStore::class )->add(
		new NewOrderNotification( $order_id )
	);
}