Automattic\WooCommerce\StoreApi\Routes\V1

AbstractCartRoute::add_response_headers │ protected │ WC 1.0

Add nonce headers to a response object.

Метод класса: AbstractCartRoute{}

Хуков нет.

Возвращает

\WP_REST_Response.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_response_headers( $response );
$response(WP_REST_Response) (обязательный)
The response object.

Код AbstractCartRoute::add_response_headers() WC 11.3.0

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( 'Cache-Control', 'no-store' );

	if ( WC()->cart instanceof \WC_Cart && \WC_Cart_Session::are_updates_enabled_for_cart( WC()->cart ) ) {
		$response->header( 'Cart-Token', $this->get_cart_token() );
		$response->header( 'Cart-Hash', WC()->cart->get_cart_hash() );
	}

	return $response;
}