WC_API_Webhooks::get_webhook()
Get the webhook for the given ID
Method of the class: WC_API_Webhooks{}
Hooks from the method
Return
Array|WP_Error
.
Usage
$WC_API_Webhooks = new WC_API_Webhooks(); $WC_API_Webhooks->get_webhook( $id, $fields );
- $id(int) (required)
- webhook ID
- $fields(array)
- -
Default: null
Changelog
Since 2.2 | Introduced. |
WC_API_Webhooks::get_webhook() WC API Webhooks::get webhook code WC 7.7.0
public function get_webhook( $id, $fields = null ) { // ensure webhook ID is valid & user has permission to read $id = $this->validate_request( $id, 'shop_webhook', 'read' ); if ( is_wp_error( $id ) ) { return $id; } $webhook = wc_get_webhook( $id ); $webhook_data = array( 'id' => $webhook->get_id(), 'name' => $webhook->get_name(), 'status' => $webhook->get_status(), 'topic' => $webhook->get_topic(), 'resource' => $webhook->get_resource(), 'event' => $webhook->get_event(), 'hooks' => $webhook->get_hooks(), 'delivery_url' => $webhook->get_delivery_url(), 'created_at' => $this->server->format_datetime( $webhook->get_date_created() ? $webhook->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times. 'updated_at' => $this->server->format_datetime( $webhook->get_date_modified() ? $webhook->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times. ); return array( 'webhook' => apply_filters( 'woocommerce_api_webhook_response', $webhook_data, $webhook, $fields, $this ) ); }