Automattic\WooCommerce\StoreApi\Utilities

CartController::throw_default_product_exceptionprotectedWC 1.0

Default exception thrown when an item cannot be added to the cart.

Method of the class: CartController{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->throw_default_product_exception( $product );
$product(WC_Product) (required)
Product object associated with the cart item.

CartController::throw_default_product_exception() code WC 10.7.0

protected function throw_default_product_exception( \WC_Product $product ) {
	$product_name = $this->get_product_name( $product );

	if ( empty( $product_name ) ) {
		$message = __( 'This item is not available for purchase.', 'woocommerce' );
	} else {
		$message = sprintf(
			/* translators: %s: product name */
			__( '"%s" is not available for purchase.', 'woocommerce' ),
			$product_name
		);
	}

	throw new RouteException(
		'woocommerce_rest_product_not_purchasable',
		esc_html( $message ),
		400
	);
}