Automattic\WooCommerce\StoreApi\Routes\V1

AbstractCartRoute::add_response_headersprotectedWC 1.0

Add nonce headers to a response object.

Method of the class: AbstractCartRoute{}

No Hooks.

Returns

\WP_REST_Response.

Usage

// protected - for code of main (parent) or child class
$result = $this->add_response_headers( $response );
$response(WP_REST_Response) (required)
The response object.

AbstractCartRoute::add_response_headers() code WC 10.8.1

protected function add_response_headers( \WP_REST_Response $response ) {
	$nonce = wp_create_nonce( 'wc_store_api' );

	$response->header( 'Nonce', $nonce );
	$response->header( 'Nonce-Timestamp', time() );
	$response->header( 'User-ID', get_current_user_id() );
	$response->header( 'Cart-Token', $this->get_cart_token() );
	$response->header( 'Cart-Hash', WC()->cart->get_cart_hash() );
	$response->header( 'Cache-Control', 'no-store' );

	return $response;
}