WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Routes

AbstractCartRoute::check_nonce() protected WC 1.0

For non-GET endpoints, require and validate a nonce to prevent CSRF attacks.

Nonces will mismatch if the logged in session cookie is different! If using a client to test, set this cookie to match the logged in cookie in your browser.

{} It's a method of the class: AbstractCartRoute{}

Return

\WP_Error|true|false.

Usage

// protected - for code of main (parent) or child class
$result = $this->check_nonce( $request );
$request(WP_REST_Request) (required)
Request object.

Code of AbstractCartRoute::check_nonce() WC 5.8.0

protected function check_nonce( \WP_REST_Request $request ) {
	$nonce = $request->get_header( 'X-WC-Store-API-Nonce' );

	if ( apply_filters( 'woocommerce_store_api_disable_nonce_check', false ) ) {
		return true;
	}

	if ( null === $nonce ) {
		return $this->get_route_error_response( 'woocommerce_rest_missing_nonce', __( 'Missing the X-WC-Store-API-Nonce header. This endpoint requires a valid nonce.', 'woocommerce' ), 401 );
	}

	if ( ! wp_verify_nonce( $nonce, 'wc_store_api' ) ) {
		return $this->get_route_error_response( 'woocommerce_rest_invalid_nonce', __( 'X-WC-Store-API-Nonce is invalid.', 'woocommerce' ), 403 );
	}

	return true;
}