Automattic\WooCommerce\Internal\Admin\Agentic

AgenticWebhookManager::mark_first_event_deliveredpublicWC 1.0

Mark first event as delivered on successful webhook delivery.

Method of the class: AgenticWebhookManager{}

No Hooks.

Returns

null. Nothing (null).

Usage

$AgenticWebhookManager = new AgenticWebhookManager();
$AgenticWebhookManager->mark_first_event_delivered( $http_args, $response, $duration, $arg, $webhook_id );
$http_args(array) (required)
HTTP request args.
$response(mixed) (required)
HTTP response.
$duration(float) (required)
Request duration.
$arg(int) (required)
First argument to the action (order_id).
$webhook_id(int) (required)
Webhook ID.

AgenticWebhookManager::mark_first_event_delivered() code WC 10.4.3

public function mark_first_event_delivered( $http_args, $response, $duration, $arg, $webhook_id ) {
	// Only proceed for successful responses.
	if ( is_wp_error( $response ) ) {
		return;
	}
	$code = wp_remote_retrieve_response_code( $response );
	if ( $code < 200 || $code >= 300 ) {
		return;
	}

	// Verify this is our webhook topic.
	$webhook = wc_get_webhook( $webhook_id );
	if ( ! $webhook || self::WEBHOOK_TOPIC !== $webhook->get_topic() ) {
		return;
	}

	// $arg contains the order_id from do_action( self::WEBHOOK_ACTION, $order_id, $order ).
	$order = wc_get_order( $arg );
	if ( ! $order ) {
		return;
	}

	if ( 'sent' !== $order->get_meta( self::FIRST_EVENT_DELIVERED_META_KEY ) ) {
		$order->update_meta_data( self::FIRST_EVENT_DELIVERED_META_KEY, 'sent' );
		$order->save();
	}
}