diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 5197683af2b..2c207512c98 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -294,6 +294,34 @@ jQuery( function( $ ) { }); }, + /** + * Ger variations fields and convert to object + * + * @param {object} fields + * + * @return {object} + */ + get_variations_fields: function( fields ) { + var data = {}, + index = 0; + + fields.each( function( i, element ) { + $.each( $( ':input', element ).serializeArray(), function( key, input ) { + var name = input.name.replace( /\[.*\]/g, '' ); + + if ( ! data.hasOwnProperty( name ) ) { + data[ name ] = {}; + } + + data[ name ][ index ] = input.value; + }); + + index++; + }); + + return data; + }, + /** * Save variations * @@ -302,20 +330,21 @@ jQuery( function( $ ) { save_variations: function() { var button = $( this ), wrapper = $( '#variable_product_options .woocommerce_variations' ), - need_update = $( '.variation-needs-update', wrapper ); + need_update = $( '.variation-needs-update', wrapper ), + data = {}; // Save only with products need update. if ( 0 < need_update.length ) { wc_meta_boxes_product_variations_ajax.block(); + data = wc_meta_boxes_product_variations_ajax.get_variations_fields( need_update ); + data.action = 'woocommerce_save_variations'; + data.security = woocommerce_admin_meta_boxes_variations.save_variations_nonce; + data.product_id = wrapper.data( 'product_id' ); + $.ajax({ url: woocommerce_admin_meta_boxes_variations.ajax_url, - data: { - action: 'woocommerce_save_variations', - security: woocommerce_admin_meta_boxes_variations.save_variations_nonce, - product_id: wrapper.data( 'product_id' ), - data: $( ':input', need_update ).serialize() - }, + data: data, type: 'POST', success: function() { // Allow change page, delete and add new variations diff --git a/assets/js/admin/meta-boxes-product-variation.min.js b/assets/js/admin/meta-boxes-product-variation.min.js index 70da45c9bd5..2441ad2d5fc 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){var b={init:function(){a("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#woocommerce-product-data").on("woocommerce_variations_loaded",this.variations_loaded)},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()},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()},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()},variations_loaded:function(){a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",a(this)).change(),a(".woocommerce_variation",a(this)).each(function(b,c){var d=a(c),e=a(".sale_price_dates_from",d).val(),f=a(".sale_price_dates_to",d).val();(""!==e||""!==f)&&a("a.sale_schedule",d).click()}),a(".woocommerce_variations .variation-needs-update",a(this)).removeClass("variation-needs-update"),a("button.save-variation-changes",a(this)).attr("disabled","disabled")}},c={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(b){var d=a(this),e=d.attr("rel"),f=d.closest(".upload_image");if(c.setting_variation_image=f,c.setting_variation_image_id=e,b.preventDefault(),d.is(".remove"))a(".upload_image_id",c.setting_variation_image).val("").change(),c.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),c.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(c.variable_image_frame)return c.variable_image_frame.uploader.uploader.param("post_id",c.setting_variation_image_id),void c.variable_image_frame.open();wp.media.model.settings.post.id=c.setting_variation_image_id,c.variable_image_frame=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"})]}),c.variable_image_frame.on("select",function(){var b=c.variable_image_frame.state().get("selection").first().toJSON(),d=b.sizes.thumbnail?b.sizes.thumbnail.url:b.url;a(".upload_image_id",c.setting_variation_image).val(b.id).change(),c.setting_variation_image.find(".upload_image_button").addClass("remove"),c.setting_variation_image.find("img").eq(0).attr("src",d),wp.media.model.settings.post.id=c.wp_media_post_id}),c.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=c.wp_media_post_id}},d={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).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 .woocommerce_variations :input",this.input_changed),a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",this.bulk_edit)},check_for_editions:function(){var b=a("#variable_product_options .woocommerce_variations .variation-needs-update");if(00?(c.push(b),f.variation_ids=c,f.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){var b=parseInt(a("#variable_product_options .woocommerce_variations").attr("data-page"),10);e.go_to_page(b,-1)})):d.unblock()}return!1},link_all_variations:function(){if(!d.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){d.block();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?(e.go_to_page(1,c),a("#variable_product_options").trigger("woocommerce_variations_added")):d.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a(".save-variation-changes").removeAttr("disabled")},bulk_edit:function(){if(!d.check_for_editions())return!1;var b,c=a("select#field_to_edit").val(),f=a("#variable_product_options .woocommerce_variations").data("product_id"),g={},h=0;switch(c){case"delete_all":window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning)&&(g.allowed=!0,h=-1*parseInt(a("#variable_product_options .woocommerce_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null!=b&&(g.value=b.indexOf("%")>=0?accounting.unformat(b.replace(/\%/,""),woocommerce_admin.mon_decimal_point)+"%":accounting.unformat(b,woocommerce_admin.mon_decimal_point));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":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=b&&(g.value=b);break;case"variable_sale_schedule":g.date_from=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),g.date_to=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===g.date_from&&(g.date_from=!1),null===g.date_to&&(g.date_to=!1);break;default:a("select#field_to_edit").trigger(c)}d.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_bulk_edit_variations",security:woocommerce_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:f,bulk_action:c,data:g},type:"POST",success:function(){e.go_to_page(1,h)}})}},e={init:function(){a(document.body).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},set_paginav:function(b){var c=a("#variable_product_options .woocommerce_variations"),d=parseInt(c.attr("data-total"),10),e=d+b,f=a(".variations-pagenav"),g=a(".displaying-num",f),h=Math.ceil(e/woocommerce_admin_meta_boxes_variations.variations_per_page),i="";c.attr("data-total",e),g.text(1===e?woocommerce_admin_meta_boxes_variations.i18n_item.replace("%qty%",e):woocommerce_admin_meta_boxes_variations.i18n_items.replace("%qty%",e)),c.attr("data-total_pages",h),a(".total-pages",f).text(h);for(var j=1;h>=j;j++)i+='";a(".page-selector",f).empty().html(i),0===e?f.closest(".toolbar").hide():f.closest(".toolbar").show()},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&d.check_for_editions()},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).first().change()},go_to_page:function(a,b){a=a||1,b=b||0,e.set_paginav(b),e.set_page(a)},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options .woocommerce_variations");d.check_for_editions()?(e.change_classes(b,parseInt(c.attr("data-total_pages"),10)),d.load_variations(b)):a(this).val(parseInt(c.attr("data-page"),10))},first_page:function(){return e.check_is_enabled(this)&&e.set_page(1),!1},prev_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.attr("data-page"),10)-1,d=c>0?c:1;e.set_page(d)}return!1},next_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.attr("data-total_pages"),10),d=parseInt(b.attr("data-page"),10)+1,f=c>=d?d:c;e.set_page(f)}return!1},last_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations").attr("data-total_pages");e.set_page(b)}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file +jQuery(function(a){var b={init:function(){a("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#woocommerce-product-data").on("woocommerce_variations_loaded",this.variations_loaded)},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()},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()},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()},variations_loaded:function(){a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",a(this)).change(),a(".woocommerce_variation",a(this)).each(function(b,c){var d=a(c),e=a(".sale_price_dates_from",d).val(),f=a(".sale_price_dates_to",d).val();(""!==e||""!==f)&&a("a.sale_schedule",d).click()}),a(".woocommerce_variations .variation-needs-update",a(this)).removeClass("variation-needs-update"),a("button.save-variation-changes",a(this)).attr("disabled","disabled")}},c={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(b){var d=a(this),e=d.attr("rel"),f=d.closest(".upload_image");if(c.setting_variation_image=f,c.setting_variation_image_id=e,b.preventDefault(),d.is(".remove"))a(".upload_image_id",c.setting_variation_image).val("").change(),c.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),c.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(c.variable_image_frame)return c.variable_image_frame.uploader.uploader.param("post_id",c.setting_variation_image_id),void c.variable_image_frame.open();wp.media.model.settings.post.id=c.setting_variation_image_id,c.variable_image_frame=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"})]}),c.variable_image_frame.on("select",function(){var b=c.variable_image_frame.state().get("selection").first().toJSON(),d=b.sizes.thumbnail?b.sizes.thumbnail.url:b.url;a(".upload_image_id",c.setting_variation_image).val(b.id).change(),c.setting_variation_image.find(".upload_image_button").addClass("remove"),c.setting_variation_image.find("img").eq(0).attr("src",d),wp.media.model.settings.post.id=c.wp_media_post_id}),c.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=c.wp_media_post_id}},d={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).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 .woocommerce_variations :input",this.input_changed),a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",this.bulk_edit)},check_for_editions:function(){var b=a("#variable_product_options .woocommerce_variations .variation-needs-update");if(00?(c.push(b),f.variation_ids=c,f.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){var b=parseInt(a("#variable_product_options .woocommerce_variations").attr("data-page"),10);e.go_to_page(b,-1)})):d.unblock()}return!1},link_all_variations:function(){if(!d.check_for_editions())return!1;if(window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){d.block();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?(e.go_to_page(1,c),a("#variable_product_options").trigger("woocommerce_variations_added")):d.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a(".save-variation-changes").removeAttr("disabled")},bulk_edit:function(){if(!d.check_for_editions())return!1;var b,c=a("select#field_to_edit").val(),f=a("#variable_product_options .woocommerce_variations").data("product_id"),g={},h=0;switch(c){case"delete_all":window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning)&&(g.allowed=!0,h=-1*parseInt(a("#variable_product_options .woocommerce_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null!=b&&(g.value=b.indexOf("%")>=0?accounting.unformat(b.replace(/\%/,""),woocommerce_admin.mon_decimal_point)+"%":accounting.unformat(b,woocommerce_admin.mon_decimal_point));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":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=b&&(g.value=b);break;case"variable_sale_schedule":g.date_from=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),g.date_to=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===g.date_from&&(g.date_from=!1),null===g.date_to&&(g.date_to=!1);break;default:a("select#field_to_edit").trigger(c)}d.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_bulk_edit_variations",security:woocommerce_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:f,bulk_action:c,data:g},type:"POST",success:function(){e.go_to_page(1,h)}})}},e={init:function(){a(document.body).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},set_paginav:function(b){var c=a("#variable_product_options .woocommerce_variations"),d=parseInt(c.attr("data-total"),10),e=d+b,f=a(".variations-pagenav"),g=a(".displaying-num",f),h=Math.ceil(e/woocommerce_admin_meta_boxes_variations.variations_per_page),i="";c.attr("data-total",e),g.text(1===e?woocommerce_admin_meta_boxes_variations.i18n_item.replace("%qty%",e):woocommerce_admin_meta_boxes_variations.i18n_items.replace("%qty%",e)),c.attr("data-total_pages",h),a(".total-pages",f).text(h);for(var j=1;h>=j;j++)i+='";a(".page-selector",f).empty().html(i),0===e?f.closest(".toolbar").hide():f.closest(".toolbar").show()},check_is_enabled:function(b){return!a(b).hasClass("disabled")&&d.check_for_editions()},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).first().change()},go_to_page:function(a,b){a=a||1,b=b||0,e.set_paginav(b),e.set_page(a)},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options .woocommerce_variations");d.check_for_editions()?(e.change_classes(b,parseInt(c.attr("data-total_pages"),10)),d.load_variations(b)):a(this).val(parseInt(c.attr("data-page"),10))},first_page:function(){return e.check_is_enabled(this)&&e.set_page(1),!1},prev_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.attr("data-page"),10)-1,d=c>0?c:1;e.set_page(d)}return!1},next_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations"),c=parseInt(b.attr("data-total_pages"),10),d=parseInt(b.attr("data-page"),10)+1,f=c>=d?d:c;e.set_page(f)}return!1},last_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options .woocommerce_variations").attr("data-total_pages");e.set_page(b)}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 5520faf5bf3..6fe344c13dc 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -2469,46 +2469,47 @@ class WC_AJAX { check_ajax_referer( 'save-variations', 'security' ); // Check permissions again and make sure we have what we need - if ( ! current_user_can( 'edit_products' ) || empty( $_POST['data'] ) || empty( $_POST['product_id'] ) ) { + if ( ! current_user_can( 'edit_products' ) || empty( $_POST ) || empty( $_POST['product_id'] ) ) { die( -1 ); } global $wpdb; - parse_str( $_POST['data'], $data ); $product_id = absint( $_POST['product_id'] ); $attributes = (array) maybe_unserialize( get_post_meta( $product_id, '_product_attributes', true ) ); - if ( isset( $data['variable_sku'] ) ) { - $variable_post_id = $data['variable_post_id']; - $variable_sku = $data['variable_sku']; - $variable_regular_price = $data['variable_regular_price']; - $variable_sale_price = $data['variable_sale_price']; - $upload_image_id = $data['upload_image_id']; - $variable_download_limit = $data['variable_download_limit']; - $variable_download_expiry = $data['variable_download_expiry']; - $variable_shipping_class = $data['variable_shipping_class']; - $variable_tax_class = isset( $data['variable_tax_class'] ) ? $data['variable_tax_class'] : array(); - $variable_menu_order = $data['variation_menu_order']; - $variable_sale_price_dates_from = $data['variable_sale_price_dates_from']; - $variable_sale_price_dates_to = $data['variable_sale_price_dates_to']; + die(); - $variable_weight = isset( $data['variable_weight'] ) ? $data['variable_weight'] : array(); - $variable_length = isset( $data['variable_length'] ) ? $data['variable_length'] : array(); - $variable_width = isset( $data['variable_width'] ) ? $data['variable_width'] : array(); - $variable_height = isset( $data['variable_height'] ) ? $data['variable_height'] : array(); - $variable_enabled = isset( $data['variable_enabled'] ) ? $data['variable_enabled'] : array(); - $variable_is_virtual = isset( $data['variable_is_virtual'] ) ? $data['variable_is_virtual'] : array(); - $variable_is_downloadable = isset( $data['variable_is_downloadable'] ) ? $data['variable_is_downloadable'] : array(); + if ( isset( $_POST['variable_sku'] ) ) { + $variable_post_id = $_POST['variable_post_id']; + $variable_sku = $_POST['variable_sku']; + $variable_regular_price = $_POST['variable_regular_price']; + $variable_sale_price = $_POST['variable_sale_price']; + $upload_image_id = $_POST['upload_image_id']; + $variable_download_limit = $_POST['variable_download_limit']; + $variable_download_expiry = $_POST['variable_download_expiry']; + $variable_shipping_class = $_POST['variable_shipping_class']; + $variable_tax_class = isset( $_POST['variable_tax_class'] ) ? $_POST['variable_tax_class'] : array(); + $variable_menu_order = $_POST['variation_menu_order']; + $variable_sale_price_dates_from = $_POST['variable_sale_price_dates_from']; + $variable_sale_price_dates_to = $_POST['variable_sale_price_dates_to']; - $variable_manage_stock = isset( $data['variable_manage_stock'] ) ? $data['variable_manage_stock'] : array(); - $variable_stock = isset( $data['variable_stock'] ) ? $data['variable_stock'] : array(); - $variable_backorders = isset( $data['variable_backorders'] ) ? $data['variable_backorders'] : array(); - $variable_stock_status = isset( $data['variable_stock_status'] ) ? $data['variable_stock_status'] : array(); + $variable_weight = isset( $_POST['variable_weight'] ) ? $_POST['variable_weight'] : array(); + $variable_length = isset( $_POST['variable_length'] ) ? $_POST['variable_length'] : array(); + $variable_width = isset( $_POST['variable_width'] ) ? $_POST['variable_width'] : array(); + $variable_height = isset( $_POST['variable_height'] ) ? $_POST['variable_height'] : array(); + $variable_enabled = isset( $_POST['variable_enabled'] ) ? $_POST['variable_enabled'] : array(); + $variable_is_virtual = isset( $_POST['variable_is_virtual'] ) ? $_POST['variable_is_virtual'] : array(); + $variable_is_downloadable = isset( $_POST['variable_is_downloadable'] ) ? $_POST['variable_is_downloadable'] : array(); - $variable_description = isset( $data['variable_description'] ) ? $data['variable_description'] : array(); + $variable_manage_stock = isset( $_POST['variable_manage_stock'] ) ? $_POST['variable_manage_stock'] : array(); + $variable_stock = isset( $_POST['variable_stock'] ) ? $_POST['variable_stock'] : array(); + $variable_backorders = isset( $_POST['variable_backorders'] ) ? $_POST['variable_backorders'] : array(); + $variable_stock_status = isset( $_POST['variable_stock_status'] ) ? $_POST['variable_stock_status'] : array(); - $max_loop = max( array_keys( $data['variable_post_id'] ) ); + $variable_description = isset( $_POST['variable_description'] ) ? $_POST['variable_description'] : array(); + + $max_loop = max( array_keys( $_POST['variable_post_id'] ) ); for ( $i = 0; $i <= $max_loop; $i ++ ) { @@ -2660,8 +2661,8 @@ class WC_AJAX { update_post_meta( $variation_id, '_download_expiry', wc_clean( $variable_download_expiry[ $i ] ) ); $files = array(); - $file_names = isset( $data['_wc_variation_file_names'][ $variation_id ] ) ? array_map( 'wc_clean', $data['_wc_variation_file_names'][ $variation_id ] ) : array(); - $file_urls = isset( $data['_wc_variation_file_urls'][ $variation_id ] ) ? array_map( 'wc_clean', $data['_wc_variation_file_urls'][ $variation_id ] ) : array(); + $file_names = isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? array_map( 'wc_clean', $_POST['_wc_variation_file_names'][ $variation_id ] ) : array(); + $file_urls = isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? array_map( 'wc_clean', $_POST['_wc_variation_file_urls'][ $variation_id ] ) : array(); $file_url_size = sizeof( $file_urls ); $allowed_file_types = get_allowed_mime_types(); @@ -2732,9 +2733,9 @@ class WC_AJAX { if ( $attribute['is_taxonomy'] ) { // Don't use wc_clean as it destroys sanitized characters - $value = isset( $data[ $attribute_key ][ $i ] ) ? sanitize_title( stripslashes( $data[ $attribute_key ][ $i ] ) ) : ''; + $value = isset( $_POST[ $attribute_key ][ $i ] ) ? sanitize_title( stripslashes( $_POST[ $attribute_key ][ $i ] ) ) : ''; } else { - $value = isset( $data[ $attribute_key ][ $i ] ) ? wc_clean( stripslashes( $data[ $attribute_key ][ $i ] ) ) : ''; + $value = isset( $_POST[ $attribute_key ][ $i ] ) ? wc_clean( stripslashes( $_POST[ $attribute_key ][ $i ] ) ) : ''; } update_post_meta( $variation_id, $attribute_key, $value ); @@ -2763,8 +2764,8 @@ class WC_AJAX { if ( $attribute['is_variation'] ) { // Don't use wc_clean as it destroys sanitized characters - if ( isset( $data[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) { - $value = sanitize_title( trim( stripslashes( $data[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) ); + if ( isset( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) { + $value = sanitize_title( trim( stripslashes( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) ) ); } else { $value = ''; }