WC_Webhook::deliver()
Deliver the webhook payload using wp_safe_remote_request().
Method of the class: WC_Webhook{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Webhook = new WC_Webhook(); $WC_Webhook->deliver( $arg );
- $arg(mixed) (required)
- First hook argument.
Changelog
Since 2.2.0 | Introduced. |
WC_Webhook::deliver() WC Webhook::deliver code WC 9.3.3
public function deliver( $arg ) { $start_time = microtime( true ); $payload = $this->build_payload( $arg ); // Setup request args. $http_args = array( 'method' => 'POST', 'timeout' => MINUTE_IN_SECONDS, 'redirection' => 0, 'httpversion' => '1.0', 'blocking' => true, 'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', Constants::get_constant( 'WC_VERSION' ), $GLOBALS['wp_version'] ), 'body' => trim( wp_json_encode( $payload ) ), 'headers' => array( 'Content-Type' => 'application/json', ), 'cookies' => array(), ); $http_args = apply_filters( 'woocommerce_webhook_http_args', $http_args, $arg, $this->get_id() ); // Add custom headers. $delivery_id = $this->get_new_delivery_id(); $http_args['headers']['X-WC-Webhook-Source'] = home_url( '/' ); // Since 2.6.0. $http_args['headers']['X-WC-Webhook-Topic'] = $this->get_topic(); $http_args['headers']['X-WC-Webhook-Resource'] = $this->get_resource(); $http_args['headers']['X-WC-Webhook-Event'] = $this->get_event(); $http_args['headers']['X-WC-Webhook-Signature'] = $this->generate_signature( $http_args['body'] ); $http_args['headers']['X-WC-Webhook-ID'] = $this->get_id(); $http_args['headers']['X-WC-Webhook-Delivery-ID'] = $delivery_id; // Webhook away! $response = wp_safe_remote_request( $this->get_delivery_url(), $http_args ); $duration = NumberUtil::round( microtime( true ) - $start_time, 5 ); $this->log_delivery( $delivery_id, $http_args, $response, $duration ); do_action( 'woocommerce_webhook_delivery', $http_args, $response, $duration, $arg, $this->get_id() ); }