Allows avoiding performance bottlenecks caused by get_available_variation().
Co-authored-by: Daniel Kudwien <daniel@netzstrategen.com>
This commit is contained in:
parent
d663631f32
commit
8584ac2638
|
@ -282,9 +282,10 @@ class WC_Product_Variable extends WC_Product {
|
|||
/**
|
||||
* Get an array of available variations for the current product.
|
||||
*
|
||||
* @param bool $render_variations Allows avoiding performance bottlenecks caused by get_available_variation().
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_variations() {
|
||||
public function get_available_variations($render_variations = true) {
|
||||
|
||||
$variation_ids = $this->get_children();
|
||||
$available_variations = array();
|
||||
|
@ -307,10 +308,17 @@ class WC_Product_Variable extends WC_Product {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( $render_variations ) {
|
||||
$available_variations[] = $this->get_available_variation( $variation );
|
||||
} else {
|
||||
$available_variations[] = $variation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( $render_variations ) {
|
||||
$available_variations = array_values( array_filter( $available_variations ) );
|
||||
}
|
||||
|
||||
return $available_variations;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue