1 /*global inlineEditPost, woocommerce_admin, woocommerce_quick_edit */
3 $( '#the-list' ).on( 'click', '.editinline', function() {
5 inlineEditPost.revert();
7 var post_id = $( this ).closest( 'tr' ).attr( 'id' );
9 post_id = post_id.replace( 'post-', '' );
11 var $wc_inline_data = $( '#woocommerce_inline_' + post_id );
13 var sku = $wc_inline_data.find( '.sku' ).text(),
14 regular_price = $wc_inline_data.find( '.regular_price' ).text(),
15 sale_price = $wc_inline_data.find( '.sale_price ').text(),
16 weight = $wc_inline_data.find( '.weight' ).text(),
17 length = $wc_inline_data.find( '.length' ).text(),
18 width = $wc_inline_data.find( '.width' ).text(),
19 height = $wc_inline_data.find( '.height' ).text(),
20 shipping_class = $wc_inline_data.find( '.shipping_class' ).text(),
21 visibility = $wc_inline_data.find( '.visibility' ).text(),
22 stock_status = $wc_inline_data.find( '.stock_status' ).text(),
23 stock = $wc_inline_data.find( '.stock' ).text(),
24 featured = $wc_inline_data.find( '.featured' ).text(),
25 manage_stock = $wc_inline_data.find( '.manage_stock' ).text(),
26 menu_order = $wc_inline_data.find( '.menu_order' ).text(),
27 tax_status = $wc_inline_data.find( '.tax_status' ).text(),
28 tax_class = $wc_inline_data.find( '.tax_class' ).text(),
29 backorders = $wc_inline_data.find( '.backorders' ).text();
31 var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point ),
32 formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point );
34 $( 'input[name="_sku"]', '.inline-edit-row' ).val( sku );
35 $( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price );
36 $( 'input[name="_sale_price"]', '.inline-edit-row' ).val( formatted_sale_price );
37 $( 'input[name="_weight"]', '.inline-edit-row' ).val( weight );
38 $( 'input[name="_length"]', '.inline-edit-row' ).val( length );
39 $( 'input[name="_width"]', '.inline-edit-row' ).val( width );
40 $( 'input[name="_height"]', '.inline-edit-row' ).val( height );
42 $( 'select[name="_shipping_class"] option:selected', '.inline-edit-row' ).attr( 'selected', false ).change();
43 $( 'select[name="_shipping_class"] option[value="' + shipping_class + '"]' ).attr( 'selected', 'selected' ).change();
45 $( 'input[name="_stock"]', '.inline-edit-row' ).val( stock );
46 $( 'input[name="menu_order"]', '.inline-edit-row' ).val( menu_order );
48 $( 'select[name="_tax_status"] option, select[name="_tax_class"] option, select[name="_visibility"] option, select[name="_stock_status"] option, select[name="_backorders"] option' ).removeAttr( 'selected' );
50 $( 'select[name="_tax_status"] option[value="' + tax_status + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
51 $( 'select[name="_tax_class"] option[value="' + tax_class + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
52 $( 'select[name="_visibility"] option[value="' + visibility + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
53 $( 'select[name="_stock_status"] option[value="' + stock_status + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
54 $( 'select[name="_backorders"] option[value="' + backorders + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
56 if ( 'yes' === featured ) {
57 $( 'input[name="_featured"]', '.inline-edit-row' ).attr( 'checked', 'checked' );
59 $( 'input[name="_featured"]', '.inline-edit-row' ).removeAttr( 'checked' );
62 if ( 'yes' === manage_stock ) {
63 $( '.stock_qty_field', '.inline-edit-row' ).show().removeAttr( 'style' );
64 $( 'input[name="_manage_stock"]', '.inline-edit-row' ).attr( 'checked', 'checked' );
66 $( '.stock_qty_field', '.inline-edit-row' ).hide();
67 $( 'input[name="_manage_stock"]', '.inline-edit-row' ).removeAttr( 'checked' );
70 // Conditional display
71 var product_type = $wc_inline_data.find( '.product_type' ).text(),
72 product_is_virtual = $wc_inline_data.find( '.product_is_virtual' ).text();
74 if ( 'simple' === product_type || 'external' === product_type ) {
75 $( '.price_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
77 $( '.price_fields', '.inline-edit-row' ).hide();
80 if ( 'yes' === product_is_virtual ) {
81 $( '.dimension_fields', '.inline-edit-row' ).hide();
83 $( '.dimension_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
86 if ( 'grouped' === product_type ) {
87 $( '.stock_fields', '.inline-edit-row' ).hide();
89 $( '.stock_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
92 // Rename core strings
93 $( 'input[name="comment_status"]' ).parent().find( '.checkbox-title' ).text( woocommerce_quick_edit.strings.allow_reviews );
96 $( '#the-list' ).on( 'change', '.inline-edit-row input[name="_manage_stock"]', function() {
98 if ( $( this ).is( ':checked' ) ) {
99 $( '.stock_qty_field', '.inline-edit-row' ).show().removeAttr( 'style' );
101 $( '.stock_qty_field', '.inline-edit-row' ).hide();
106 $( '#wpbody' ).on( 'click', '#doaction, #doaction2', function() {
107 $( 'input.text', '.inline-edit-row' ).val( '' );
108 $( '#woocommerce-fields' ).find( 'select' ).prop( 'selectedIndex', 0 );
109 $( '#woocommerce-fields-bulk' ).find( '.inline-edit-group .change-input' ).hide();
112 $( '#wpbody' ).on( 'change', '#woocommerce-fields-bulk .inline-edit-group .change_to', function() {
114 if ( 0 < $( this ).val() ) {
115 $( this ).closest( 'div' ).find( '.change-input' ).show();
117 $( this ).closest( 'div' ).find( '.change-input' ).hide();