WC_Product_Variable::variation_is_available()privateWC 1.0

Check if a given variation is currently available.

Method of the class: WC_Product_Variable{}

Return

true|false. True if the variation is available, false otherwise.

Usage

// private - for code of main (parent) class only
$result = $this->variation_is_available( $variation );
$variation(WC_Product_Variation) (required)
Variation to check.

WC_Product_Variable::variation_is_available() code WC 9.3.3

private function variation_is_available( WC_Product_Variation $variation ) {
	// Hide out of stock variations if 'Hide out of stock items from the catalog' is checked.
	if ( ! $variation || ! $variation->exists() || ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && ! $variation->is_in_stock() ) ) {
		return false;
	}

	// Filter 'woocommerce_hide_invisible_variations' to optionally hide invisible variations (disabled variations and variations with empty price).
	if ( apply_filters( 'woocommerce_hide_invisible_variations', true, $this->get_id(), $variation ) && ! $variation->variation_is_visible() ) {
		return false;
	}

	return true;
}