woocommerce_cart_item_is_purchasable filter-hookWC 7.0.0

Allow 3rd parties to override this item's is_purchasable() result with cart item data.

Usage

add_filter( 'woocommerce_cart_item_is_purchasable', 'wp_kama_woocommerce_cart_item_is_purchasable_filter', 10, 4 );

/**
 * Function for `woocommerce_cart_item_is_purchasable` filter-hook.
 * 
 * @param bool       $is_purchasable If false, the item will not be added to the cart.
 * @param string     $key            Cart item key.
 * @param array      $values         Cart item values e.g. quantity and product_id.
 * @param WC_Product $product        The product being added to the cart.
 *
 * @return bool
 */
function wp_kama_woocommerce_cart_item_is_purchasable_filter( $is_purchasable, $key, $values, $product ){

	// filter...
	return $is_purchasable;
}
$is_purchasable(true|false)
If false, the item will not be added to the cart.
Default: product's is_purchasable() status
$key(string)
Cart item key.
$values(array)
Cart item values e.g. quantity and product_id.
$product(WC_Product)
The product being added to the cart.

Changelog

Since 7.0.0 Introduced.

Where the hook is called

WC_Cart_Session::get_cart_from_session()
woocommerce_cart_item_is_purchasable
woocommerce/includes/class-wc-cart-session.php 175
} elseif ( ! apply_filters( 'woocommerce_cart_item_is_purchasable', $product->is_purchasable(), $key, $values, $product ) ) {

Where the hook is used in WooCommerce

Usage not found.