Automattic\WooCommerce\Internal\Admin\Agentic

AgenticWebhookManager::customize_webhook_payloadpublicWC 1.0

Customize webhook payload for Agentic topics.

Method of the class: AgenticWebhookManager{}

No Hooks.

Returns

Array. Modified payload.

Usage

$AgenticWebhookManager = new AgenticWebhookManager();
$AgenticWebhookManager->customize_webhook_payload( $payload, $resource_type, $resource_id, $webhook_id );
$payload(array) (required)
Original payload.
$resource_type(string) (required)
Resource type.
$resource_id(int) (required)
Resource ID.
$webhook_id(int) (required)
Webhook ID.

AgenticWebhookManager::customize_webhook_payload() code WC 10.4.3

public function customize_webhook_payload( $payload, $resource_type, $resource_id, $webhook_id ) {
	$webhook = wc_get_webhook( $webhook_id );
	if ( ! $webhook ) {
		return $payload;
	}

	$topic = $webhook->get_topic();

	// Check if this is one of our Agentic topics.
	if ( self::WEBHOOK_TOPIC !== $topic ) {
		return $payload;
	}

	// Get the order.
	$order = wc_get_order( $resource_id );
	if ( ! $order ) {
		return $payload;
	}

	$is_first_event = 'sent' !== $order->get_meta( self::FIRST_EVENT_DELIVERED_META_KEY );
	$event          = $is_first_event ? 'order_create' : 'order_update';

	// Build ACP-compliant payload.
	return $this->payload_builder->build_payload( $event, $order );
}