Allows avoiding performance bottlenecks caused by get_available_variation().

Co-authored-by: Daniel Kudwien <daniel@netzstrategen.com>
This commit is contained in:
Bogdan Arizancu 2020-04-21 11:57:20 +02:00 committed by Daniel Kudwien
parent d663631f32
commit 8584ac2638
1 changed files with 11 additions and 3 deletions

View File

@ -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;
}