woocommerce_cart_item_is_purchasable
Allow 3rd parties to override this item's is_purchasable() result with cart item data.
Использование
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.
По умолчанию: product's is_purchasable() status - $key(строка)
- Cart item key.
- $values(массив)
- Cart item values e.g. quantity and product_id.
- $product(WC_Product)
- The product being added to the cart.
Список изменений
| С версии 7.0.0 | Введена. |
Где вызывается хук
woocommerce_cart_item_is_purchasable
woocommerce/includes/class-wc-cart-session.php 185
} elseif ( ! apply_filters( 'woocommerce_cart_item_is_purchasable', $product->is_purchasable(), $key, $values, $product ) ) {