woocommerce_cart_item_is_purchasable
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
woocommerce_cart_item_is_purchasable
woocommerce/includes/class-wc-cart-session.php 178
} elseif ( ! apply_filters( 'woocommerce_cart_item_is_purchasable', $product->is_purchasable(), $key, $values, $product ) ) {