Automattic\WooCommerce\Internal\ShopperLists
ShopperListItem::is_purchasable
Whether the product can be added to the cart. Mirrors the catalog gate (is_purchasable() && is_in_stock()), but additionally requires the row to be live and rejects password-gated products (self or parent) — cart-add can't prompt for a password.
Method of the class: ShopperListItem{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ShopperListItem = new ShopperListItem(); $ShopperListItem->is_purchasable(): bool;
ShopperListItem::is_purchasable() ShopperListItem::is purchasable code WC 11.0.1
public function is_purchasable(): bool {
$product = $this->get_product();
if ( ! $this->is_live() || ! $product ) {
return false;
}
if ( ! $product->is_purchasable() || ! $product->is_in_stock() ) {
return false;
}
if ( ! empty( $product->get_post_password() ) ) {
return false;
}
$parent_id = $product->get_parent_id();
if ( $parent_id > 0 ) {
$parent = wc_get_product( $parent_id );
if ( $parent instanceof \WC_Product && ! empty( $parent->get_post_password() ) ) {
return false;
}
}
return true;
}