WC_Webhook::get_wp_api_payload()
Get WP API integration payload.
Method of the class: WC_Webhook{}
No Hooks.
Return
Array
.
Usage
// private - for code of main (parent) class only $result = $this->get_wp_api_payload( $resource, $resource_id, $event );
- $resource(string) (required)
- Resource type.
- $resource_id(int) (required)
- Resource ID.
- $event(string) (required)
- Event type.
Changelog
Since 3.0.0 | Introduced. |
WC_Webhook::get_wp_api_payload() WC Webhook::get wp api payload code WC 9.6.1
private function get_wp_api_payload( $resource, $resource_id, $event ) { switch ( $resource ) { case 'coupon': case 'customer': case 'order': case 'product': // Bulk and quick edit action hooks return a product object instead of an ID. if ( 'product' === $resource && 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) { $resource_id = $resource_id->get_id(); } $version = str_replace( 'wp_api_', '', $this->get_api_version() ); $payload = wc_get_container()->get( RestApiUtil::class )->get_endpoint_data( "/wc/{$version}/{$resource}s/{$resource_id}" ); break; // Custom topics include the first hook argument. case 'action': $payload = array( 'action' => current( $this->get_hooks() ), 'arg' => $resource_id, ); break; default: $payload = array(); break; } return $payload; }