wc_webhook_execute_queue()WC 4.4.0

Process the web hooks at the end of the request.

Hooks from the function

Return

null. Nothing (null).

Usage

wc_webhook_execute_queue();

Changelog

Since 4.4.0 Introduced.

wc_webhook_execute_queue() code WC 9.4.2

function wc_webhook_execute_queue() {
	global $wc_queued_webhooks;
	if ( empty( $wc_queued_webhooks ) ) {
		return;
	}

	foreach ( $wc_queued_webhooks as $data ) {
		// Webhooks are processed in the background by default
		// so as to avoid delays or failures in delivery from affecting the
		// user who triggered it.
		if ( apply_filters( 'woocommerce_webhook_deliver_async', true, $data['webhook'], $data['arg'] ) ) {

			$queue_args = array(
				'webhook_id' => $data['webhook']->get_id(),
				'arg'        => $data['arg'],
			);

			$next_scheduled_date = WC()->queue()->get_next( 'woocommerce_deliver_webhook_async', $queue_args, 'woocommerce-webhooks' );

			// Make webhooks unique - only schedule one webhook every 10 minutes to maintain backward compatibility with WP Cron behaviour seen in WC < 3.5.0.
			if ( is_null( $next_scheduled_date ) || $next_scheduled_date->getTimestamp() >= ( 600 + gmdate( 'U' ) ) ) {
				WC()->queue()->add( 'woocommerce_deliver_webhook_async', $queue_args, 'woocommerce-webhooks' );
			}
		} else {
			// Deliver immediately.
			$data['webhook']->deliver( $data['arg'] );
		}
	}
}