diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 7e5fe927feb..a15be9c6f7f 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -21,145 +21,6 @@ jQuery( function ( $ ) { } }; - // Add a variation - $( '#variable_product_options' ).on( 'click', 'button.add_variation', function () { - - $('.woocommerce_variations').block({ - message: null, - overlayCSS: { - background: '#fff', - opacity: 0.6 - } - }); - - var loop = $('.woocommerce_variation').size(); - - var data = { - action: 'woocommerce_add_variation', - post_id: woocommerce_admin_meta_boxes_variations.post_id, - loop: loop, - security: woocommerce_admin_meta_boxes_variations.add_variation_nonce - }; - - $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) { - - $( '.woocommerce_variations' ).append( response ); - - $( '.tips' ).tipTip({ - 'attribute': 'data-tip', - 'fadeIn': 50, - 'fadeOut': 50 - }); - - $( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change(); - $( '.woocommerce_variations' ).unblock(); - $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' ); - }); - - return false; - - }); - - $( '#variable_product_options').on( 'click', 'button.link_all_variations', function () { - - var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_link_all_variations ); - - if ( answer ) { - - $( '#variable_product_options' ).block({ - message: null, - overlayCSS: { - background: '#fff', - opacity: 0.6 - } - }); - - var data = { - action: 'woocommerce_link_all_variations', - post_id: woocommerce_admin_meta_boxes_variations.post_id, - security: woocommerce_admin_meta_boxes_variations.link_variation_nonce - }; - - $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function ( response ) { - - var count = parseInt( response, 10 ); - - if ( 1 === count ) { - window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variation_added ); - } else if ( 0 === count || count > 1 ) { - window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variations_added ); - } else { - window.alert( woocommerce_admin_meta_boxes_variations.i18n_no_variations_added ); - } - - if ( count > 0 ) { - var this_page = window.location.toString(); - - this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_admin_meta_boxes_variations.post_id + '&action=edit&' ); - - $( '#variable_product_options' ).load( this_page + ' #variable_product_options_inner', function () { - $( '#variable_product_options' ).unblock(); - $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' ); - - $( '.tips' ).tipTip({ - 'attribute': 'data-tip', - 'fadeIn': 50, - 'fadeOut': 50 - }); - } ); - } else { - $( '#variable_product_options' ).unblock(); - } - }); - } - return false; - }); - - $( '#variable_product_options' ).on( 'click', 'button.remove_variation', function ( e ) { - e.preventDefault(); - var answer = window.confirm( woocommerce_admin_meta_boxes_variations.i18n_remove_variation ); - if ( answer ) { - - var el = $( this ).parent().parent(); - - var variation = $( this ).attr( 'rel' ); - - if ( variation > 0 ) { - - $( el ).block({ - message: null, - overlayCSS: { - background: '#fff', - opacity: 0.6 - } - }); - - var variation_ids = []; - variation_ids.push( variation ); - - var data = { - action: 'woocommerce_remove_variations', - variation_ids: variation_ids, - security: woocommerce_admin_meta_boxes_variations.delete_variations_nonce - }; - - $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function() { - // Success - $( el ).fadeOut( '300', function () { - $( el ).remove(); - }); - }); - - } else { - $( el ).fadeOut( '300', function () { - $( el ).remove(); - }); - } - - } - return false; - }); - $( '.wc-metaboxes-wrapper' ).on( 'click', 'a.bulk_edit', function () { var bulk_edit = $( 'select#field_to_edit' ).val(), checkbox, @@ -428,13 +289,38 @@ jQuery( function ( $ ) { var wc_meta_boxes_product_variations_ajax = { /** - * Initialize products variations meta box + * Initialize variations ajax methods */ init: function() { $( 'li.variations_tab a' ).on( 'click', this.initial_load ); + + $( '#variable_product_options' ) + .on( 'click', 'button.add_variation', this.add_variation ) + .on( 'click', 'button.remove_variation', this.remove_variation ) + .on( 'click', 'button.link_all_variations', this.link_all_variations ); + $( 'body' ).on( 'change', '#variable_product_options_inner .woocommerce_variations :input', this.input_changed ); }, + /** + * Check if have some edition before leave the page + * + * @return {bool} + */ + check_for_editions: function() { + var wrapper = $( '#variable_product_options_inner .woocommerce_variations' ); + + if ( 'true' === wrapper.attr( 'data-edited' ) ) { + if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_edited_variations ) ) { + wrapper.attr( 'data-edited', false ); + } else { + return false; + } + } + + return true; + }, + /** * Initial load variations * @@ -478,13 +364,144 @@ jQuery( function ( $ ) { }, type: 'POST', success: function( response ) { - wrapper.empty().append( response ).attr( 'page', page ); + wrapper.empty().append( response ).attr( 'data-page', page ); $( '#woocommerce-product-data' ).unblock(); } }); }, + /** + * Add variation + * + * @return {bool} + */ + add_variation: function() { + if ( ! wc_meta_boxes_product_variations_ajax.check_for_editions() ) { + return false; + } + + $( '#woocommerce-product-data' ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + + var data = { + action: 'woocommerce_add_variation', + post_id: woocommerce_admin_meta_boxes_variations.post_id, + loop: $( '.woocommerce_variation' ).size(), + security: woocommerce_admin_meta_boxes_variations.add_variation_nonce + }; + + $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function() { + wc_meta_boxes_product_variations_pagenav.set_page( 1 ); + + $( '#woocommerce-product-data' ).unblock(); + $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' ); + }); + + return false; + }, + + /** + * Remove variation + * + * @return {bool} + */ + remove_variation: function() { + if ( ! wc_meta_boxes_product_variations_ajax.check_for_editions() ) { + return false; + } + + if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_remove_variation ) ) { + var variation = $( this ).attr( 'rel' ), + variation_ids = [], + data = { + action: 'woocommerce_remove_variations' + }; + + $( '#woocommerce-product-data' ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + + if ( 0 < variation ) { + variation_ids.push( variation ); + + data.variation_ids = variation_ids; + data.security = woocommerce_admin_meta_boxes_variations.delete_variations_nonce; + + $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function() { + var current = parseInt( $( '#variable_product_options_inner .woocommerce_variations' ).attr( 'data-page' ), 10 ); + + console.log( current ); + + wc_meta_boxes_product_variations_pagenav.set_page( current ); + }); + + } else { + $( '#woocommerce-product-data' ).unblock(); + } + } + + return false; + }, + + /** + * Link all variations (or at least try :p) + * + * @return {bool} + */ + link_all_variations: function() { + if ( ! wc_meta_boxes_product_variations_ajax.check_for_editions() ) { + return false; + } + + if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_link_all_variations ) ) { + $( '#woocommerce-product-data' ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + + var data = { + action: 'woocommerce_link_all_variations', + post_id: woocommerce_admin_meta_boxes_variations.post_id, + security: woocommerce_admin_meta_boxes_variations.link_variation_nonce + }; + + $.post( woocommerce_admin_meta_boxes_variations.ajax_url, data, function( response ) { + var count = parseInt( response, 10 ); + + if ( 1 === count ) { + window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variation_added ); + } else if ( 0 === count || count > 1 ) { + window.alert( count + ' ' + woocommerce_admin_meta_boxes_variations.i18n_variations_added ); + } else { + window.alert( woocommerce_admin_meta_boxes_variations.i18n_no_variations_added ); + } + + if ( count > 0 ) { + wc_meta_boxes_product_variations_pagenav.set_page( 1 ); + + $( '#variable_product_options' ).trigger( 'woocommerce_variations_added' ); + } else { + $( '#woocommerce-product-data' ).unblock(); + } + }); + } + + return false; + }, + /** * Add new class when have changes in some input */ @@ -509,32 +526,13 @@ jQuery( function ( $ ) { $( '.variations-pagenav .last-page' ).on( 'click', this.last_page ); }, - /** - * Check if have some edition before leave the page - * - * @return {bool} - */ - check_for_editions: function() { - var wrapper = $( '#variable_product_options_inner .woocommerce_variations' ); - - if ( 'true' === wrapper.attr( 'data-edited' ) ) { - if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_edited_variations ) ) { - wrapper.attr( 'data-edited', false ); - } else { - return false; - } - } - - return true; - }, - /** * Check button if enabled and if don't have editions * * @return {bool} */ check_is_enabled: function( current ) { - return ! $( current ).hasClass( 'disabled' ) && wc_meta_boxes_product_variations_pagenav.check_for_editions(); + return ! $( current ).hasClass( 'disabled' ) && wc_meta_boxes_product_variations_ajax.check_for_editions(); }, /** @@ -558,6 +556,13 @@ jQuery( function ( $ ) { } }, + /** + * Set page + */ + set_page: function( page ) { + $( '.variations-pagenav .page-selector' ).val( page ).change(); + }, + /** * Paginav pagination selector */ @@ -565,11 +570,11 @@ jQuery( function ( $ ) { var selected = parseInt( $( this ).val(), 10 ), wrapper = $( '#variable_product_options_inner .woocommerce_variations' ); - if ( wc_meta_boxes_product_variations_pagenav.check_for_editions() ) { + if ( wc_meta_boxes_product_variations_ajax.check_for_editions() ) { wc_meta_boxes_product_variations_pagenav.change_classes(); wc_meta_boxes_product_variations_ajax.load_variations( selected ); } else { - $( this ).val( parseInt( wrapper.attr( 'page' ), 10 ) ); + $( this ).val( parseInt( wrapper.data( 'page' ), 10 ) ); } }, @@ -580,7 +585,7 @@ jQuery( function ( $ ) { */ first_page: function() { if ( wc_meta_boxes_product_variations_pagenav.check_is_enabled( this ) ) { - $( '.variations-pagenav .page-selector' ).val( 1 ).change(); + wc_meta_boxes_product_variations_pagenav.set_page( 1 ); } return false; @@ -594,10 +599,10 @@ jQuery( function ( $ ) { prev_page: function() { if ( wc_meta_boxes_product_variations_pagenav.check_is_enabled( this ) ) { var wrapper = $( '#variable_product_options_inner .woocommerce_variations' ), - prev_page = parseInt( wrapper.attr( 'page' ), 10 ) - 1, + prev_page = parseInt( wrapper.data( 'page' ), 10 ) - 1, new_page = ( 0 < prev_page ) ? prev_page : 1; - $( '.variations-pagenav .page-selector' ).val( new_page ).change(); + wc_meta_boxes_product_variations_pagenav.set_page( new_page ); } return false; @@ -612,10 +617,10 @@ jQuery( function ( $ ) { if ( wc_meta_boxes_product_variations_pagenav.check_is_enabled( this ) ) { var wrapper = $( '#variable_product_options_inner .woocommerce_variations' ), total_pages = wrapper.data( 'total_pages' ), - next_page = parseInt( wrapper.attr( 'page' ), 10 ) + 1, + next_page = parseInt( wrapper.data( 'page' ), 10 ) + 1, new_page = ( total_pages >= next_page ) ? next_page : total_pages; - $( '.variations-pagenav .page-selector' ).val( new_page ).change(); + wc_meta_boxes_product_variations_pagenav.set_page( new_page ); } return false; @@ -630,7 +635,7 @@ jQuery( function ( $ ) { if ( wc_meta_boxes_product_variations_pagenav.check_is_enabled( this ) ) { var last_page = $( '#variable_product_options_inner .woocommerce_variations' ).data( 'total_pages' ); - $( '.variations-pagenav .page-selector' ).val( last_page ).change(); + wc_meta_boxes_product_variations_pagenav.set_page( last_page ); } return false; diff --git a/assets/js/admin/meta-boxes-product-variation.min.js b/assets/js/admin/meta-boxes-product-variation.min.js index 5fc5a50b707..4ee904ae830 100644 --- a/assets/js/admin/meta-boxes-product-variation.min.js +++ b/assets/js/admin/meta-boxes-product-variation.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){a(".woocommerce_variations .woocommerce_variation").each(function(b,c){a(".variation_menu_order",c).val(parseInt(a(c).index(".woocommerce_variations .woocommerce_variation"),10))})}var c={items:".woocommerce_variation",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,c){c.item.removeAttr("style"),b()}};a("#variable_product_options").on("click","button.add_variation",function(){a(".woocommerce_variations").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b=a(".woocommerce_variation").size(),c={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:b,security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};return a.post(woocommerce_admin_meta_boxes_variations.ajax_url,c,function(b){a(".woocommerce_variations").append(b),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50}),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a(".woocommerce_variations").unblock(),a("#variable_product_options").trigger("woocommerce_variations_added")}),!1}),a("#variable_product_options").on("click","button.link_all_variations",function(){var b=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations);if(b){a("#variable_product_options").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,c,function(b){var c=parseInt(b,10);if(window.alert(1===c?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added:0===c||c>1?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added:woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0){var d=window.location.toString();d=d.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes_variations.post_id+"&action=edit&"),a("#variable_product_options").load(d+" #variable_product_options_inner",function(){a("#variable_product_options").unblock(),a("#variable_product_options").trigger("woocommerce_variations_added"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50})})}else a("#variable_product_options").unblock()})}return!1}),a("#variable_product_options").on("click","button.remove_variation",function(b){b.preventDefault();var c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation);if(c){var d=a(this).parent().parent(),e=a(this).attr("rel");if(e>0){a(d).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var f=[];f.push(e);var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(d).fadeOut("300",function(){a(d).remove()})})}else a(d).fadeOut("300",function(){a(d).remove()})}return!1}),a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var b,c,d,e=a("select#field_to_edit").val();switch(e){case"toggle_enabled":b=a('input[name^="variable_enabled"]'),b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":b=a('input[name^="variable_is_downloadable"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_downloadable").change();break;case"toggle_virtual":b=a('input[name^="variable_is_virtual"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_virtual").change();break;case"toggle_manage_stock":b=a('input[name^="variable_manage_stock"]'),b.attr("checked",!b.attr("checked")),a("input.variable_manage_stock").change();break;case"delete_all":if(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations),c&&(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning))){var f=[];a(".woocommerce_variations .woocommerce_variation").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var b=a(this).attr("rel");b>0&&f.push(b)});var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){a(".woocommerce_variations .woocommerce_variation").remove()})})}break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":var h;if(h=0===e.lastIndexOf("variable_regular_price",0)?"variable_regular_price":"variable_sale_price",d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null==d)return;d=d.toString(),a(':input[name^="'+h+'"]').not('[name*="dates"]').each(function(){var b,c,f=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);c=d.indexOf("%")>=0?f/100*accounting.unformat(d.replace(/\%/,""),woocommerce_admin.mon_decimal_point):accounting.unformat(d,woocommerce_admin.mon_decimal_point),b=-1!==e.indexOf("increase")?f+c:f-c,a(this).val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,woocommerce_admin_meta_boxes.currency_format_thousand_sep,woocommerce_admin_meta_boxes.currency_format_decimal_sep)).change()});break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=d&&a(':input[name^="'+e+'"]').not('[name*="dates"]').val(d).change();break;case"variable_sale_schedule":var i=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),j=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),k=!1;null!=i&&""!==i&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_from"]').val(i).change(),k=!0),null!=j&&""!==j&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_to"]').val(j).change(),k=!0),k||a(".woocommerce_variable_attributes .cancel_sale_schedule").click();break;default:a("select#field_to_edit").trigger(e)}}),a("#variable_product_options").on("change","input.variable_is_downloadable",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()}),a("#variable_product_options").on("change","input.variable_is_virtual",function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()}),a("#variable_product_options").on("change","input.variable_manage_stock",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()}),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#variable_product_options").on("woocommerce_variations_added",function(){a(".woocommerce_variations").sortable(c)}),a(".woocommerce_variations").sortable(c);var d,e,f,g=wp.media.model.settings.post.id;a("#variable_product_options").on("click",".upload_image_button",function(b){var c=a(this),h=c.attr("rel"),i=c.closest(".upload_image");if(f=i,e=h,b.preventDefault(),c.is(".remove"))f.find(".upload_image_id").val(""),f.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),f.find(".upload_image_button").removeClass("remove");else{if(d)return d.uploader.uploader.param("post_id",e),void d.open();wp.media.model.settings.post.id=e,d=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),d.on("select",function(){var a=d.state().get("selection").first().toJSON(),b=a.sizes.thumbnail?a.sizes.thumbnail.url:a.url;f.find(".upload_image_id").val(a.id),f.find(".upload_image_button").addClass("remove"),f.find("img").eq(0).attr("src",b),wp.media.model.settings.post.id=g}),d.open()}}),a("a.add_media").on("click",function(){wp.media.model.settings.post.id=g});var h={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("body").on("change","#variable_product_options_inner .woocommerce_variations :input",this.input_changed)},initial_load:function(){0===a("#variable_product_options_inner .woocommerce_variations .woocommerce_variation").length&&h.load_variations()},load_variations:function(b,c){b=b||1,c=c||woocommerce_admin_meta_boxes_variations.variations_per_page;var d=a("#variable_product_options_inner .woocommerce_variations");a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_load_variations",security:woocommerce_admin_meta_boxes_variations.load_variations_nonce,product_id:d.data("product_id"),attributes:d.data("attributes"),page:b,per_page:c},type:"POST",success:function(c){d.empty().append(c).attr("page",b),a("#woocommerce-product-data").unblock()}})},input_changed:function(){a("#variable_product_options_inner .woocommerce_variations").attr("data-edited",!0)}},i={init:function(){a(".variations-pagenav .page-selector").on("change",this.page_selector),a(".variations-pagenav .first-page").on("click",this.first_page),a(".variations-pagenav .prev-page").on("click",this.prev_page),a(".variations-pagenav .next-page").on("click",this.next_page),a(".variations-pagenav .last-page").on("click",this.last_page)},check_for_editions:function(){var b=a("#variable_product_options_inner .woocommerce_variations");if("true"===b.attr("data-edited")){if(!window.confirm(woocommerce_admin_meta_boxes_variations.i18n_edited_variations))return!1;b.attr("data-edited",!1)}return!0},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&i.check_for_editions()},change_classes:function(b,c){1===b?(a(".variations-pagenav .first-page").addClass("disabled"),a(".variations-pagenav .prev-page").addClass("disabled")):(a(".variations-pagenav .first-page").removeClass("disabled"),a(".variations-pagenav .prev-page").removeClass("disabled")),c===b?(a(".variations-pagenav .next-page").addClass("disabled"),a(".variations-pagenav .last-page").addClass("disabled")):(a(".variations-pagenav .next-page").removeClass("disabled"),a(".variations-pagenav .last-page").removeClass("disabled"))},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options_inner .woocommerce_variations");i.check_for_editions()?(i.change_classes(),h.load_variations(b)):a(this).val(parseInt(c.attr("page"),10))},first_page:function(){return i.check_is_enabled(this)&&a(".variations-pagenav .page-selector").val(1).change(),!1},prev_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations"),c=parseInt(b.attr("page"),10)-1,d=c>0?c:1;a(".variations-pagenav .page-selector").val(d).change()}return!1},next_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations"),c=b.data("total_pages"),d=parseInt(b.attr("page"),10)+1,e=c>=d?d:c;a(".variations-pagenav .page-selector").val(e).change()}return!1},last_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations").data("total_pages");a(".variations-pagenav .page-selector").val(b).change()}return!1}};h.init(),i.init()}); \ No newline at end of file +jQuery(function(a){function b(){a(".woocommerce_variations .woocommerce_variation").each(function(b,c){a(".variation_menu_order",c).val(parseInt(a(c).index(".woocommerce_variations .woocommerce_variation"),10))})}var c={items:".woocommerce_variation",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,c){c.item.removeAttr("style"),b()}};a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var b,c,d,e=a("select#field_to_edit").val();switch(e){case"toggle_enabled":b=a('input[name^="variable_enabled"]'),b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":b=a('input[name^="variable_is_downloadable"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_downloadable").change();break;case"toggle_virtual":b=a('input[name^="variable_is_virtual"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_virtual").change();break;case"toggle_manage_stock":b=a('input[name^="variable_manage_stock"]'),b.attr("checked",!b.attr("checked")),a("input.variable_manage_stock").change();break;case"delete_all":if(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations),c&&(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning))){var f=[];a(".woocommerce_variations .woocommerce_variation").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var b=a(this).attr("rel");b>0&&f.push(b)});var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){a(".woocommerce_variations .woocommerce_variation").remove()})})}break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":var h;if(h=0===e.lastIndexOf("variable_regular_price",0)?"variable_regular_price":"variable_sale_price",d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null==d)return;d=d.toString(),a(':input[name^="'+h+'"]').not('[name*="dates"]').each(function(){var b,c,f=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);c=d.indexOf("%")>=0?f/100*accounting.unformat(d.replace(/\%/,""),woocommerce_admin.mon_decimal_point):accounting.unformat(d,woocommerce_admin.mon_decimal_point),b=-1!==e.indexOf("increase")?f+c:f-c,a(this).val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,woocommerce_admin_meta_boxes.currency_format_thousand_sep,woocommerce_admin_meta_boxes.currency_format_decimal_sep)).change()});break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=d&&a(':input[name^="'+e+'"]').not('[name*="dates"]').val(d).change();break;case"variable_sale_schedule":var i=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),j=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),k=!1;null!=i&&""!==i&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_from"]').val(i).change(),k=!0),null!=j&&""!==j&&(a(".woocommerce_variable_attributes .sale_schedule").click(),a(':input[name^="variable_sale_price_dates_to"]').val(j).change(),k=!0),k||a(".woocommerce_variable_attributes .cancel_sale_schedule").click();break;default:a("select#field_to_edit").trigger(e)}}),a("#variable_product_options").on("change","input.variable_is_downloadable",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()}),a("#variable_product_options").on("change","input.variable_is_virtual",function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()}),a("#variable_product_options").on("change","input.variable_manage_stock",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()}),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#variable_product_options").on("woocommerce_variations_added",function(){a(".woocommerce_variations").sortable(c)}),a(".woocommerce_variations").sortable(c);var d,e,f,g=wp.media.model.settings.post.id;a("#variable_product_options").on("click",".upload_image_button",function(b){var c=a(this),h=c.attr("rel"),i=c.closest(".upload_image");if(f=i,e=h,b.preventDefault(),c.is(".remove"))f.find(".upload_image_id").val(""),f.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),f.find(".upload_image_button").removeClass("remove");else{if(d)return d.uploader.uploader.param("post_id",e),void d.open();wp.media.model.settings.post.id=e,d=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),d.on("select",function(){var a=d.state().get("selection").first().toJSON(),b=a.sizes.thumbnail?a.sizes.thumbnail.url:a.url;f.find(".upload_image_id").val(a.id),f.find(".upload_image_button").addClass("remove"),f.find("img").eq(0).attr("src",b),wp.media.model.settings.post.id=g}),d.open()}}),a("a.add_media").on("click",function(){wp.media.model.settings.post.id=g});var h={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.add_variation",this.add_variation).on("click","button.remove_variation",this.remove_variation).on("click","button.link_all_variations",this.link_all_variations),a("body").on("change","#variable_product_options_inner .woocommerce_variations :input",this.input_changed)},check_for_editions:function(){var b=a("#variable_product_options_inner .woocommerce_variations");if("true"===b.attr("data-edited")){if(!window.confirm(woocommerce_admin_meta_boxes_variations.i18n_edited_variations))return!1;b.attr("data-edited",!1)}return!0},initial_load:function(){0===a("#variable_product_options_inner .woocommerce_variations .woocommerce_variation").length&&h.load_variations()},load_variations:function(b,c){b=b||1,c=c||woocommerce_admin_meta_boxes_variations.variations_per_page;var d=a("#variable_product_options_inner .woocommerce_variations");a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_load_variations",security:woocommerce_admin_meta_boxes_variations.load_variations_nonce,product_id:d.data("product_id"),attributes:d.data("attributes"),page:b,per_page:c},type:"POST",success:function(c){d.empty().append(c).attr("data-page",b),a("#woocommerce-product-data").unblock()}})},add_variation:function(){if(!h.check_for_editions())return!1;a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:a(".woocommerce_variation").size(),security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};return a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(){i.set_page(1),a("#woocommerce-product-data").unblock(),a("#variable_product_options").trigger("woocommerce_variations_added")}),!1},remove_variation:function(){if(!h.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation)){var b=a(this).attr("rel"),c=[],d={action:"woocommerce_remove_variations"};a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),b>0?(c.push(b),d.variation_ids=c,d.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,d,function(){var b=parseInt(a("#variable_product_options_inner .woocommerce_variations").attr("data-page"),10);console.log(b),i.set_page(b)})):a("#woocommerce-product-data").unblock()}return!1},link_all_variations:function(){if(!h.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(b){var c=parseInt(b,10);window.alert(1===c?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added:0===c||c>1?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added:woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0?(i.set_page(1),a("#variable_product_options").trigger("woocommerce_variations_added")):a("#woocommerce-product-data").unblock()})}return!1},input_changed:function(){a("#variable_product_options_inner .woocommerce_variations").attr("data-edited",!0)}},i={init:function(){a(".variations-pagenav .page-selector").on("change",this.page_selector),a(".variations-pagenav .first-page").on("click",this.first_page),a(".variations-pagenav .prev-page").on("click",this.prev_page),a(".variations-pagenav .next-page").on("click",this.next_page),a(".variations-pagenav .last-page").on("click",this.last_page)},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&h.check_for_editions()},change_classes:function(b,c){1===b?(a(".variations-pagenav .first-page").addClass("disabled"),a(".variations-pagenav .prev-page").addClass("disabled")):(a(".variations-pagenav .first-page").removeClass("disabled"),a(".variations-pagenav .prev-page").removeClass("disabled")),c===b?(a(".variations-pagenav .next-page").addClass("disabled"),a(".variations-pagenav .last-page").addClass("disabled")):(a(".variations-pagenav .next-page").removeClass("disabled"),a(".variations-pagenav .last-page").removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).change()},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options_inner .woocommerce_variations");h.check_for_editions()?(i.change_classes(),h.load_variations(b)):a(this).val(parseInt(c.data("page"),10))},first_page:function(){return i.check_is_enabled(this)&&i.set_page(1),!1},prev_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations"),c=parseInt(b.data("page"),10)-1,d=c>0?c:1;i.set_page(d)}return!1},next_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations"),c=b.data("total_pages"),d=parseInt(b.data("page"),10)+1,e=c>=d?d:c;i.set_page(e)}return!1},last_page:function(){if(i.check_is_enabled(this)){var b=a("#variable_product_options_inner .woocommerce_variations").data("total_pages");i.set_page(b)}return!1}};h.init(),i.init()}); \ No newline at end of file diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php index 0a1d0415ef8..c6cf023ad7c 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php @@ -628,9 +628,10 @@ class WC_Meta_Box_Product_Data { } } - $variations_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'product_variation'", $post->ID ) ); + $variations_count = absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'product_variation'", $post->ID ) ) ); $variations_per_page = absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 10 ) ); $variations_total_pages = ceil( $variations_count / $variations_per_page ); + ?>
@@ -701,7 +702,7 @@ class WC_Meta_Box_Product_Data {
-
+

diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index de2e647ccb7..feb255ce4e7 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -2364,8 +2364,8 @@ class WC_AJAX { 'post_status' => array( 'private', 'publish' ), 'posts_per_page' => $per_page, 'paged' => $page, - 'orderby' => 'menu_order', - 'order' => 'asc', + 'orderby' => 'ID', + 'order' => 'DESC', 'post_parent' => $product_id );