WC_Webhook::build_payload( mixed $resource_id )
Build the payload data for the webhook.
Description Description
Parameters Parameters
- $resource_id
-
(Required) First hook argument, typically the resource ID.
Return Return
(mixed) Payload data.
Source Source
File: includes/class-wc-webhook.php
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() ); }
Changelog Changelog
Version | Description |
---|---|
2.2.0 | Introduced. |