Fix link variations on new posts. Closes #1925.
This commit is contained in:
parent
d9dbaa70c9
commit
0da50add7b
|
@ -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 + ' <?php _e( "variation added", 'woocommerce' ); ?>');
|
||||
} else if (count==0 || count>1) {
|
||||
|
@ -295,7 +291,17 @@ function variable_product_type_options() {
|
|||
alert('<?php _e( "No variations added", 'woocommerce' ); ?>');
|
||||
}
|
||||
|
||||
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=<?php echo $post->ID; ?>&action=edit&' );
|
||||
|
||||
$('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() {
|
||||
$('#variable_product_options').unblock();
|
||||
} );
|
||||
} else {
|
||||
$('#variable_product_options').unblock();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in New Issue