diff --git a/admin/post-types/writepanels/writepanel-product-type-variable.php b/admin/post-types/writepanels/writepanel-product-type-variable.php index ca762f33d44..3324a4f0c93 100644 --- a/admin/post-types/writepanels/writepanel-product-type-variable.php +++ b/admin/post-types/writepanels/writepanel-product-type-variable.php @@ -283,10 +283,6 @@ function variable_product_type_options() { var count = parseInt( response ); - if (count>0) { - jQuery('.woocommerce_variations').load( window.location + ' .woocommerce_variations > *' ); - } - if (count==1) { alert( count + ' '); } else if (count==0 || count>1) { @@ -295,7 +291,17 @@ function variable_product_type_options() { alert(''); } - jQuery('#variable_product_options').unblock(); + if (count>0) { + var this_page = window.location.toString(); + + this_page = this_page.replace( 'post-new.php?', 'post.php?post=ID; ?>&action=edit&' ); + + $('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() { + $('#variable_product_options').unblock(); + } ); + } else { + $('#variable_product_options').unblock(); + } }); } diff --git a/classes/class-wc-product-factory.php b/classes/class-wc-product-factory.php index 4e21450fdcb..25928372517 100644 --- a/classes/class-wc-product-factory.php +++ b/classes/class-wc-product-factory.php @@ -35,7 +35,9 @@ class WC_Product_Factory { $product_id = absint( $the_product->ID ); $post_type = $the_product->post_type; - if ( 'product_variation' == $post_type ) { + if ( isset( $args['product_type'] ) ) { + $product_type = $args['product_type']; + } elseif ( 'product_variation' == $post_type ) { $product_type = 'variation'; } else { $terms = get_the_terms( $product_id, 'product_type' ); diff --git a/classes/class-wc-product-variable.php b/classes/class-wc-product-variable.php index 895bcac7ab1..034608d37d4 100644 --- a/classes/class-wc-product-variable.php +++ b/classes/class-wc-product-variable.php @@ -174,21 +174,21 @@ class WC_Product_Variable extends WC_Product { */ function get_children() { - if (!is_array($this->children)) : + 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 ( false === ( $this->children = get_transient( $transient_name ) ) ) { $this->children = get_posts( 'post_parent=' . $this->id . '&post_type=product_variation&orderby=menu_order&order=ASC&fields=ids&post_status=any&numberposts=-1' ); set_transient( $transient_name, $this->children ); - endif; + } - endif; + } return (array) $this->children; } diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php index 1aadad64efb..57c0cff1a17 100644 --- a/woocommerce-ajax.php +++ b/woocommerce-ajax.php @@ -640,7 +640,7 @@ function woocommerce_link_all_variations() { $variations = array(); - $_product = get_product( $post_id ); + $_product = get_product( $post_id, array( 'product_type' => 'variable' ) ); // Put variation attributes into an array foreach ( $_product->get_attributes() as $attribute ) { @@ -662,13 +662,12 @@ function woocommerce_link_all_variations() { $options = array_map('trim', $options); $variations[ $attribute_field_name ] = $options; - } // Quit out if none were found if ( sizeof( $variations ) == 0 ) die(); - // Get existing variations so we don't create duplicated + // Get existing variations so we don't create duplicates $available_variations = array(); foreach( $_product->get_children() as $child_id ) {