WC_Product_Variable::get_available_variations()
Get an array of available variations for the current product.
Method of the class: WC_Product_Variable{}
Hooks from the method
Return
Array[]|WC_Product_Variation[]
.
Usage
$WC_Product_Variable = new WC_Product_Variable(); $WC_Product_Variable->get_available_variations( $return );
- $return(string)
- The format to return the results in. Can be 'array' to return an array of variation data or 'objects' for the product objects.
Default: 'array'
WC_Product_Variable::get_available_variations() WC Product Variable::get available variations code WC 9.4.2
public function get_available_variations( $return = 'array' ) { $variation_ids = $this->get_children(); $available_variations = array(); if ( is_callable( '_prime_post_caches' ) ) { _prime_post_caches( $variation_ids ); } foreach ( $variation_ids as $variation_id ) { $variation = wc_get_product( $variation_id ); // 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() ) ) { continue; } // 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() ) { continue; } if ( 'array' === $return ) { $available_variations[] = $this->get_available_variation( $variation ); } else { $available_variations[] = $variation; } } if ( 'array' === $return ) { $available_variations = array_values( array_filter( $available_variations ) ); } return $available_variations; }