diff --git a/assets/js/admin/meta-boxes-product.js b/assets/js/admin/meta-boxes-product.js index 04ac0f04780..02d2df6c5cc 100644 --- a/assets/js/admin/meta-boxes-product.js +++ b/assets/js/admin/meta-boxes-product.js @@ -278,66 +278,38 @@ jQuery( function( $ ){ }); // Add rows - $('button.add_attribute').on('click', function(){ + $( 'button.add_attribute' ).on('click', function(){ + var size = $( '.product_attributes .woocommerce_attribute' ).size(); + var attribute = $( 'select.attribute_taxonomy' ).val(); + var $wrapper = $( this ).closest( '#product_attributes' ).find( '.product_attributes' ); + var product_type = $( 'select#product-type' ).val(); + var data = { + action : 'woocommerce_add_attribute', + taxonomy : attribute, + i : size, + security : woocommerce_admin_meta_boxes.add_attribute_nonce + }; - var size = $('.product_attributes .woocommerce_attribute').size(); + $wrapper.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); - var attribute_type = $('select.attribute_taxonomy').val(); + $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { + $wrapper.append( response ); - if ( ! attribute_type ) { + if ( product_type !== 'variable' ) { + $wrapper.find( '.enable_variation' ).hide(); + } - var product_type = $('select#product-type').val(); - if (product_type!='variable') enable_variation = 'style="display:none;"'; else enable_variation = ''; - - // Add custom attribute row - $('.product_attributes').append('
\ -

\ - \ -
\ - \ -

\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
\ - \ - \ - \ - \ - \ - \ - \ -
\ - \ -
\ -
\ - \ -
\ -
\ -
'); - - } else { - - // Reveal taxonomy row - var thisrow = $('.product_attributes .woocommerce_attribute.' + attribute_type); - $('.product_attributes').append( $(thisrow) ); - $(thisrow).show().find('.woocommerce_attribute_data').show(); + $wrapper.find( 'select.multiselect' ).chosen(); attribute_row_indexes(); - $('select.attribute_taxonomy').find('option[value="' + attribute_type + '"]').attr('disabled','disabled'); + $wrapper.unblock(); + }); + if ( attribute ) { + $( 'select.attribute_taxonomy' ).find( 'option[value="' + attribute + '"]' ).attr( 'disabled','disabled' ); + $( 'select.attribute_taxonomy' ).val( '' ); } - $('select.attribute_taxonomy').val(''); + return false; }); $('.product_attributes').on('blur', 'input.attribute_name', function(){ @@ -399,8 +371,8 @@ jQuery( function( $ ){ $('.product_attributes').block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); - var attribute = $(this).attr('data-attribute'); - var $wrapper = $(this).closest('.woocommerce_attribute_data'); + var $wrapper = $(this).closest('.woocommerce_attribute'); + var attribute = $wrapper.data('taxonomy'); var new_attribute_name = prompt( woocommerce_admin_meta_boxes.new_attribute_prompt ); if ( new_attribute_name ) { @@ -432,7 +404,6 @@ jQuery( function( $ ){ } return false; - }); // Save attributes and update variations diff --git a/assets/js/admin/meta-boxes-product.min.js b/assets/js/admin/meta-boxes-product.min.js index ec075765e42..85934674b55 100644 --- a/assets/js/admin/meta-boxes-product.min.js +++ b/assets/js/admin/meta-boxes-product.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){var b=a("select#product-type").val(),c=a("input#_virtual:checked").size(),d=a("input#_downloadable:checked").size(),e=".hide_if_downloadable, .hide_if_virtual",f=".show_if_downloadable, .show_if_virtual, .show_if_external";a.each(woocommerce_admin_meta_boxes.product_types,function(a,b){e=e+", .hide_if_"+b,f=f+", .show_if_"+b}),a(e).show(),a(f).hide(),d&&a(".show_if_downloadable").show(),c&&a(".show_if_virtual").show(),a(".show_if_"+b).show(),d&&a(".hide_if_downloadable").hide(),c&&a(".hide_if_virtual").hide(),a(".hide_if_"+b).hide(),a("input#_manage_stock").change()}function c(){a(".product_attributes .woocommerce_attribute").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index(".product_attributes .woocommerce_attribute")))})}a(function(){a('[id$="-all"] > ul.categorychecklist').each(function(){var b=a(this),c=b.find(":checked").first();if(c.length){var d=b.find("input").position().top,e=c.position().top;b.closest(".tabs-panel").scrollTop(e-d+5)}})}),a("#upsell_product_data").bind("keypress",function(a){return 13==a.keyCode?!1:void 0}),a(".type_box").appendTo("#woocommerce-product-data h3.hndle span"),a(function(){a("#woocommerce-product-data h3.hndle").unbind("click.postboxes"),jQuery("#woocommerce-product-data").on("click","h3.hndle",function(b){a(b.target).filter("input, option, label, select").length||a("#woocommerce-product-data").toggleClass("closed")})}),a("#catalog-visibility .edit-catalog-visibility").click(function(){return a("#catalog-visibility-select").is(":hidden")&&(a("#catalog-visibility-select").slideDown("fast"),a(this).hide()),!1}),a("#catalog-visibility .save-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility .edit-catalog-visibility").show();var b=(a("input[name=_visibility]:checked").val(),a("input[name=_visibility]:checked").attr("data-label"));return a("input[name=_featured]").is(":checked")&&(b=b+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")),a("#catalog-visibility-display").text(b),!1}),a("#catalog-visibility .cancel-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility .edit-catalog-visibility").show();var b=a("#current_visibility").val(),c=a("#current_featured").val();a("input[name=_visibility]").removeAttr("checked"),a("input[name=_visibility][value="+b+"]").attr("checked","checked");var d=a("input[name=_visibility]:checked").attr("data-label");return"yes"==c?(d=d+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")):a("input[name=_featured]").removeAttr("checked"),a("#catalog-visibility-display").text(d),!1}),a("select#product-type").change(function(){var c=a(this).val();"variable"===c?(a("input#_manage_stock").change(),a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"grouped"===c?(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"external"===c&&(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")),b(),a("ul.wc-tabs li:visible").eq(0).find("a").click(),a("body").trigger("woocommerce-product-type-change",c,a(this))}).change(),a("body").on("woocommerce-product-type-change",function(b,c){"variable"!==c&&0d?-1:d>e?1:0}),a(e).each(function(b,c){a(".product_attributes").append(c)}),a(".product_attributes .woocommerce_attribute").each(function(b,c){"none"!=a(c).css("display")&&a(c).is(".taxonomy")&&a("select.attribute_taxonomy").find('option[value="'+a(c).data("taxonomy")+'"]').attr("disabled","disabled")}),a("button.add_attribute").on("click",function(){var b=a(".product_attributes .woocommerce_attribute").size(),d=a("select.attribute_taxonomy").val();if(d){var e=a(".product_attributes .woocommerce_attribute."+d);a(".product_attributes").append(a(e)),a(e).show().find(".woocommerce_attribute_data").show(),c(),a("select.attribute_taxonomy").find('option[value="'+d+'"]').attr("disabled","disabled")}else{var f=a("select#product-type").val();enable_variation="variable"!=f?'style="display:none;"':"",a(".product_attributes").append('

")}a("select.attribute_taxonomy").val("")}),a(".product_attributes").on("blur","input.attribute_name",function(){a(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(a(this).val())}),a(".product_attributes").on("click","button.select_all_attributes",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").trigger("chosen:updated"),!1}),a(".product_attributes").on("click","button.select_no_attributes",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").trigger("chosen:updated"),!1}),a(".product_attributes").on("click","button.remove_row",function(){var b=confirm(woocommerce_admin_meta_boxes.remove_attribute);if(b){var d=a(this).parent().parent();d.is(".taxonomy")?(d.find("select, input[type=text]").val(""),d.hide(),a("select.attribute_taxonomy").find('option[value="'+d.data("taxonomy")+'"]').removeAttr("disabled")):(d.find("select, input[type=text]").val(""),d.hide(),c())}return!1}),a(".product_attributes").sortable({items:".woocommerce_attribute",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,b){b.item.removeAttr("style"),c()}}),a(".product_attributes").on("click","button.add_new_attribute",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b=a(this).attr("data-attribute"),c=a(this).closest(".woocommerce_attribute_data"),d=prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(d){var e={action:"woocommerce_add_new_attribute",taxonomy:b,term:d,security:woocommerce_admin_meta_boxes.add_attribute_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(b){b.error?alert(b.error):b.slug&&(c.find("select.attribute_values").append('"),c.find("select.attribute_values").trigger("chosen:updated")),a(".product_attributes").unblock()})}else a(".product_attributes").unblock();return!1}),a(".save_attributes").on("click",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={post_id:woocommerce_admin_meta_boxes.post_id,data:a(".product_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(){var b=window.location.toString();b=b.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),a("#variable_product_options").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a("#variable_product_options").load(b+" #variable_product_options_inner",function(){a("#variable_product_options").unblock()}),a(".product_attributes").unblock()})});var f,g;jQuery(document).on("click",".upload_file_button",function(b){var c=a(this);if(g=c.closest("tr").find("td.file_url input"),b.preventDefault(),f)return void f.open();var d=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:c.data("choose"),priority:20,filterable:"uploaded"})];f=wp.media.frames.downloadable_file=wp.media({title:c.data("choose"),library:{type:""},button:{text:c.data("update")},multiple:!0,states:d}),f.on("select",function(){var a="",b=f.state().get("selection");b.map(function(b){b=b.toJSON(),b.url&&(a=b.url)}),g.val(a)}),f.on("ready",function(){f.uploader.options.uploader.params={type:"downloadable_product"}}),f.open()}),jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var h,i=a("#product_image_gallery"),j=a("#product_images_container ul.product_images");jQuery(".add_product_images").on("click","a",function(b){var c=a(this),d=i.val();return b.preventDefault(),h?void h.open():(h=wp.media.frames.product_gallery=wp.media({title:c.data("choose"),button:{text:c.data("update")},states:[new wp.media.controller.Library({title:c.data("choose"),filterable:"all",multiple:!0})]}),h.on("select",function(){var a=h.state().get("selection");a.map(function(a){a=a.toJSON(),a.id&&(d=d?d+","+a.id:a.id,j.append('
  • "))}),i.val(d)}),void h.open())}),j.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")},update:function(){var b="";a("#product_images_container ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),i.val(b)}}),a("#product_images_container").on("click","a.delete",function(){a(this).closest("li.image").remove();var b="";return a("#product_images_container ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),i.val(b),runTipTip(),!1})}); \ No newline at end of file +jQuery(function(a){function b(){var b=a("select#product-type").val(),c=a("input#_virtual:checked").size(),d=a("input#_downloadable:checked").size(),e=".hide_if_downloadable, .hide_if_virtual",f=".show_if_downloadable, .show_if_virtual, .show_if_external";a.each(woocommerce_admin_meta_boxes.product_types,function(a,b){e=e+", .hide_if_"+b,f=f+", .show_if_"+b}),a(e).show(),a(f).hide(),d&&a(".show_if_downloadable").show(),c&&a(".show_if_virtual").show(),a(".show_if_"+b).show(),d&&a(".hide_if_downloadable").hide(),c&&a(".hide_if_virtual").hide(),a(".hide_if_"+b).hide(),a("input#_manage_stock").change()}function c(){a(".product_attributes .woocommerce_attribute").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index(".product_attributes .woocommerce_attribute")))})}a(function(){a('[id$="-all"] > ul.categorychecklist').each(function(){var b=a(this),c=b.find(":checked").first();if(c.length){var d=b.find("input").position().top,e=c.position().top;b.closest(".tabs-panel").scrollTop(e-d+5)}})}),a("#upsell_product_data").bind("keypress",function(a){return 13==a.keyCode?!1:void 0}),a(".type_box").appendTo("#woocommerce-product-data h3.hndle span"),a(function(){a("#woocommerce-product-data h3.hndle").unbind("click.postboxes"),jQuery("#woocommerce-product-data").on("click","h3.hndle",function(b){a(b.target).filter("input, option, label, select").length||a("#woocommerce-product-data").toggleClass("closed")})}),a("#catalog-visibility .edit-catalog-visibility").click(function(){return a("#catalog-visibility-select").is(":hidden")&&(a("#catalog-visibility-select").slideDown("fast"),a(this).hide()),!1}),a("#catalog-visibility .save-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility .edit-catalog-visibility").show();var b=(a("input[name=_visibility]:checked").val(),a("input[name=_visibility]:checked").attr("data-label"));return a("input[name=_featured]").is(":checked")&&(b=b+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")),a("#catalog-visibility-display").text(b),!1}),a("#catalog-visibility .cancel-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility .edit-catalog-visibility").show();var b=a("#current_visibility").val(),c=a("#current_featured").val();a("input[name=_visibility]").removeAttr("checked"),a("input[name=_visibility][value="+b+"]").attr("checked","checked");var d=a("input[name=_visibility]:checked").attr("data-label");return"yes"==c?(d=d+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")):a("input[name=_featured]").removeAttr("checked"),a("#catalog-visibility-display").text(d),!1}),a("select#product-type").change(function(){var c=a(this).val();"variable"===c?(a("input#_manage_stock").change(),a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"grouped"===c?(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"external"===c&&(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")),b(),a("ul.wc-tabs li:visible").eq(0).find("a").click(),a("body").trigger("woocommerce-product-type-change",c,a(this))}).change(),a("body").on("woocommerce-product-type-change",function(b,c){"variable"!==c&&0d?-1:d>e?1:0}),a(e).each(function(b,c){a(".product_attributes").append(c)}),a(".product_attributes .woocommerce_attribute").each(function(b,c){"none"!=a(c).css("display")&&a(c).is(".taxonomy")&&a("select.attribute_taxonomy").find('option[value="'+a(c).data("taxonomy")+'"]').attr("disabled","disabled")}),a("button.add_attribute").on("click",function(){var b=a(".product_attributes .woocommerce_attribute").size(),d=a("select.attribute_taxonomy").val(),e=a(this).closest("#product_attributes").find(".product_attributes"),f=a("select#product-type").val(),g={action:"woocommerce_add_attribute",taxonomy:d,i:b,security:woocommerce_admin_meta_boxes.add_attribute_nonce};return e.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.post(woocommerce_admin_meta_boxes.ajax_url,g,function(a){e.append(a),"variable"!==f&&e.find(".enable_variation").hide(),e.find("select.multiselect").chosen(),c(),e.unblock()}),d&&(a("select.attribute_taxonomy").find('option[value="'+d+'"]').attr("disabled","disabled"),a("select.attribute_taxonomy").val("")),!1}),a(".product_attributes").on("blur","input.attribute_name",function(){a(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(a(this).val())}),a(".product_attributes").on("click","button.select_all_attributes",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").trigger("chosen:updated"),!1}),a(".product_attributes").on("click","button.select_no_attributes",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").trigger("chosen:updated"),!1}),a(".product_attributes").on("click","button.remove_row",function(){var b=confirm(woocommerce_admin_meta_boxes.remove_attribute);if(b){var d=a(this).parent().parent();d.is(".taxonomy")?(d.find("select, input[type=text]").val(""),d.hide(),a("select.attribute_taxonomy").find('option[value="'+d.data("taxonomy")+'"]').removeAttr("disabled")):(d.find("select, input[type=text]").val(""),d.hide(),c())}return!1}),a(".product_attributes").sortable({items:".woocommerce_attribute",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,b){b.item.removeAttr("style"),c()}}),a(".product_attributes").on("click","button.add_new_attribute",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b=a(this).closest(".woocommerce_attribute"),c=b.data("taxonomy"),d=prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(d){var e={action:"woocommerce_add_new_attribute",taxonomy:c,term:d,security:woocommerce_admin_meta_boxes.add_attribute_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(c){c.error?alert(c.error):c.slug&&(b.find("select.attribute_values").append('"),b.find("select.attribute_values").trigger("chosen:updated")),a(".product_attributes").unblock()})}else a(".product_attributes").unblock();return!1}),a(".save_attributes").on("click",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={post_id:woocommerce_admin_meta_boxes.post_id,data:a(".product_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(){var b=window.location.toString();b=b.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),a("#variable_product_options").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a("#variable_product_options").load(b+" #variable_product_options_inner",function(){a("#variable_product_options").unblock()}),a(".product_attributes").unblock()})});var f,g;jQuery(document).on("click",".upload_file_button",function(b){var c=a(this);if(g=c.closest("tr").find("td.file_url input"),b.preventDefault(),f)return void f.open();var d=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:c.data("choose"),priority:20,filterable:"uploaded"})];f=wp.media.frames.downloadable_file=wp.media({title:c.data("choose"),library:{type:""},button:{text:c.data("update")},multiple:!0,states:d}),f.on("select",function(){var a="",b=f.state().get("selection");b.map(function(b){b=b.toJSON(),b.url&&(a=b.url)}),g.val(a)}),f.on("ready",function(){f.uploader.options.uploader.params={type:"downloadable_product"}}),f.open()}),jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var h,i=a("#product_image_gallery"),j=a("#product_images_container ul.product_images");jQuery(".add_product_images").on("click","a",function(b){var c=a(this),d=i.val();return b.preventDefault(),h?void h.open():(h=wp.media.frames.product_gallery=wp.media({title:c.data("choose"),button:{text:c.data("update")},states:[new wp.media.controller.Library({title:c.data("choose"),filterable:"all",multiple:!0})]}),h.on("select",function(){var a=h.state().get("selection");a.map(function(a){a=a.toJSON(),a.id&&(d=d?d+","+a.id:a.id,j.append('
  • "))}),i.val(d)}),void h.open())}),j.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")},update:function(){var b="";a("#product_images_container ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),i.val(b)}}),a("#product_images_container").on("click","a.delete",function(){a(this).closest("li.image").remove();var b="";return a("#product_images_container ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),i.val(b),runTipTip(),!1})}); \ 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 2ac89676b32..43bd60c8502 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 @@ -411,181 +411,40 @@ class WC_Meta_Box_Product_Data {
    attribute_name ); - - // Ensure it exists - if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) { - continue; - } - - $i++; - - // Get product data values for current taxonomy - this contains ordering and visibility data - if ( isset( $attributes[ sanitize_title( $attribute_taxonomy_name ) ] ) ) { - $attribute = $attributes[ sanitize_title( $attribute_taxonomy_name ) ]; - } - - $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] ); - - // Get terms of this taxonomy associated with current product - $post_terms = wp_get_post_terms( $thepostid, $attribute_taxonomy_name ); - - // Any set? - $has_terms = ( is_wp_error( $post_terms ) || ! $post_terms || sizeof( $post_terms ) == 0 ) ? 0 : 1; - ?> -
    > -

    - -
    - attribute_label ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name ); ?> -

    -
    - - - - - - - - - - - - - -
    - - attribute_label ? $tax->attribute_label : $tax->attribute_name; ?> - - - - - - - attribute_type ) : ?> - - - - - - - attribute_type ) : ?> - - - -
    - -
    -
    - -
    -
    -
    -
    - -
    -

    - -
    - -

    -
    - - - - - - - - - - - - - -
    - - - - - - - -
    - -
    -
    - -
    -
    -
    -
    - @@ -597,7 +456,6 @@ class WC_Meta_Box_Product_Data { attribute_name ); $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; diff --git a/includes/admin/meta-boxes/views/html-product-attribute.php b/includes/admin/meta-boxes/views/html-product-attribute.php new file mode 100644 index 00000000000..d90950927e1 --- /dev/null +++ b/includes/admin/meta-boxes/views/html-product-attribute.php @@ -0,0 +1,79 @@ +
    +

    + +
    + +

    +
    + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + attribute_type ) : ?> + + + + + + + attribute_type ) : ?> + + " /> + + + + + + + + + + +
    + +
    +
    + +
    +
    +
    +
    \ No newline at end of file diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 263eb3a6d6c..f9b9386bd53 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -33,6 +33,7 @@ class WC_AJAX { 'checkout' => true, 'feature_product' => false, 'mark_order_status' => false, + 'add_attribute' => false, 'add_new_attribute' => false, 'remove_variation' => false, 'remove_variations' => false, @@ -404,6 +405,41 @@ class WC_AJAX { die(); } + /** + * Add an attribute row + */ + public static function add_attribute() { + ob_start(); + + check_ajax_referer( 'add-attribute', 'security' ); + + global $wc_product_attributes; + + $taxonomy = sanitize_text_field( $_POST['taxonomy'] ); + $i = absint( $_POST['i'] ); + $position = 0; + $attribute = array( + 'name' => $taxonomy, + 'value' => '', + 'is_visible' => 1, + 'is_variation' => 0, + 'is_taxonomy' => $taxonomy ? 1 : 0 + ); + + if ( $taxonomy ) { + $attribute_taxonomy = $wc_product_attributes[ $taxonomy ]; + $metabox_class = array(); + $metabox_class[] = 'taxonomy'; + $metabox_class[] = $taxonomy; + $attribute_label = wc_attribute_label( $taxonomy ); + } else { + $attribute_label = ''; + } + + include( 'admin/meta-boxes/views/html-product-attribute.php' ); + die(); + } + /** * Add a new attribute via ajax function */