Tweak get_children to look for empty transient

This commit is contained in:
Mike Jolley 2014-08-12 12:06:18 +01:00
parent fe12b330c0
commit 7f825a98ce
2 changed files with 7 additions and 11 deletions

View File

@ -83,21 +83,17 @@ class WC_Product_Grouped extends WC_Product {
* @return array
*/
public function get_children() {
if ( ! is_array( $this->children ) || empty( $this->children ) ) {
$transient_name = 'wc_product_children_ids_' . $this->id;
$this->children = get_transient( $transient_name );
if ( ! is_array( $this->children ) ) {
$this->children = array();
$transient_name = 'wc_product_children_ids_' . $this->id;
if ( false === ( $this->children = get_transient( $transient_name ) ) ) {
if ( empty( $this->children ) ) {
$this->children = get_posts( 'post_parent=' . $this->id . '&post_type=product&orderby=menu_order&order=ASC&fields=ids&post_status=publish&numberposts=-1' );
set_transient( $transient_name, $this->children, YEAR_IN_SECONDS );
}
}
return (array) $this->children;
}

View File

@ -128,11 +128,11 @@ class WC_Product_Variable extends WC_Product {
* @return array of children ids
*/
public function get_children( $visible_only = false ) {
if ( ! is_array( $this->children ) ) {
$this->children = array();
if ( ! is_array( $this->children ) || empty( $this->children ) ) {
$transient_name = 'wc_product_children_ids_' . $this->id;
$this->children = get_transient( $transient_name );
if ( false === ( $this->children = get_transient( $transient_name ) ) ) {
if ( empty( $this->children ) ) {
$args = array(
'post_parent' => $this->id,
'post_type' => 'product_variation',