WC_Webhook::build_payload()publicWC 2.2.0

Build the payload data for the webhook.

Метод класса: WC_Webhook{}

Хуки из метода

Возвращает

Разное. Payload data.

Использование

$WC_Webhook = new WC_Webhook();
$WC_Webhook->build_payload( $resource_id );
$resource_id(разное) (обязательный)
First hook argument, typically the resource ID.

Список изменений

С версии 2.2.0 Введена.

Код WC_Webhook::build_payload() WC 8.7.0

public function build_payload( $resource_id ) {
	// Build the payload with the same user context as the user who created
	// the webhook -- this avoids permission errors as background processing
	// runs with no user context.
	$current_user = get_current_user_id();
	wp_set_current_user( $this->get_user_id() );

	$resource = $this->get_resource();
	$event    = $this->get_event();

	// If a resource has been deleted, just include the ID.
	if ( 'deleted' === $event ) {
		$payload = array(
			'id' => $resource_id,
		);
	} else {
		if ( in_array( $this->get_api_version(), wc_get_webhook_rest_api_versions(), true ) ) {
			$payload = $this->get_wp_api_payload( $resource, $resource_id, $event );
		} else {
			$payload = $this->get_legacy_api_payload( $resource, $resource_id, $event );
		}
	}

	// Restore the current user.
	wp_set_current_user( $current_user );

	return apply_filters( 'woocommerce_webhook_payload', $payload, $resource, $resource_id, $this->get_id() );
}