Skip to content

Commit

Permalink
Updates to 3.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Woo committed Apr 25, 2024
1 parent 545ad6f commit ca6a3a1
Show file tree
Hide file tree
Showing 16 changed files with 3,508 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions assets/js/frontend-checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function wc_trs_display_abort_text( datas ) {
var wc_info = jQuery( '.woocommerce-info' );
var wc_chk_info = jQuery( 'form.woocommerce-checkout .woocommerce-info' );
var has_trs = false;

wc_chk_info.each( function ( idx, elem ) {
var current_elem = jQuery( elem );

// Remove the element if abort text has been found previously.
if ( 'yes' === current_elem.data('wc_trs') ) {
if ( true === has_trs ) {
current_elem.remove();
}

has_trs = true;
}
} );

if ( false === has_trs ) {
return;
}

wc_info.each( function ( idx, elem ) {
var current_elem = jQuery( elem );
if ( 'yes' === current_elem.data('wc_trs') && 1 > current_elem.parents( 'form.woocommerce-checkout' ).length ) {
current_elem.remove();
}
} );
}

jQuery( document.body ).on( 'updated_checkout checkout_error', function( datas ) {
wc_trs_display_abort_text();
} );
1 change: 1 addition & 0 deletions assets/js/frontend-checkout.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

199 changes: 199 additions & 0 deletions assets/js/table-rate-rows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*global $, woocommerce_shipping_table_rate_rows, ajaxurl */
( function( $, data, wp, ajaxurl ) {

var wc_table_rate_rows_row_template = wp.template( 'table-rate-shipping-row-template' ),
$settings_form = $( '#mainform' ),
$rates_table = $( '#shipping_rates' ),
$rates = $rates_table.find( 'tbody.table_rates' );

var wc_table_rate_rows = {
init: function() {
$settings_form
.on( 'change', '#woocommerce_table_rate_calculation_type', this.onCalculationTypeChange );
$rates_table
.on( 'change', 'select[name^="shipping_condition"]', this.onShippingConditionChange )
.on( 'change', 'input[name^="shipping_abort["]', this.onShippingAbortChange )
.on( 'click', 'a.add-rate', this.onAddRate )
.on( 'click', 'a.remove', this.onRemoveRate )
.on( 'click', 'a.dupe', this.onDupeRate );

var rates_data = $rates.data( 'rates' );

$( rates_data ).each( function( i ) {
var size = $rates.find( '.table_rate' ).length;
$rates.append( wc_table_rate_rows_row_template( {
rate: rates_data[ i ],
index: size
} ) );
} );

$( 'label[for="woocommerce_table_rate_handling_fee"], label[for="woocommerce_table_rate_max_cost"], label[for="woocommerce_table_rate_min_cost"]', $settings_form ).each( function( i, el ) {
$(el).data( 'o_label', $(el).text() );
});

$( '#woocommerce_table_rate_calculation_type, select[name^="shipping_condition"], input[name^="shipping_abort["]', $settings_form ).change();

$rates.sortable( {
items: 'tr',
cursor: 'move',
axis: 'y',
handle: 'td',
scrollSensitivity: 40,
helper: function(e,ui){
ui.children().each( function() {
$( this ).width( $(this).width() );
});
ui.css( 'left', '0' );
return ui;
},
start: function( event, ui ) {
ui.item.css('background-color','#f6f6f6');
},
stop: function( event, ui ) {
ui.item.removeAttr( 'style' );
wc_table_rate_rows.reindexRows();
}
} );
},
onCalculationTypeChange: function() {
var selected = $( this ).val();

if ( selected == 'item' ) {
$( 'td.cost_per_item input' ).attr( 'disabled', 'disabled' ).addClass('disabled');
} else {
$( 'td.cost_per_item input' ).removeAttr( 'disabled' ).removeClass('disabled');
}

if ( selected ) {
$( '#shipping_class_priorities' ).hide();
$( 'td.shipping_label, th.shipping_label' ).hide();
} else {
$( '#shipping_class_priorities' ).show();
$( 'td.shipping_label, th.shipping_label' ).show();
}

if ( ! selected ) {
$( '#shipping_class_priorities span.description.per_order' ).show();
$( '#shipping_class_priorities span.description.per_class' ).hide();
}

var label_text = data.i18n.order;

if ( selected == 'item' ) {
label_text = data.i18n.item;
} else if ( selected == 'line' ) {
label_text = data.i18n.line_item;
} else if ( selected == 'class' ) {
label_text = data.i18n.class;
}

$('label[for="woocommerce_table_rate_handling_fee"], label[for="woocommerce_table_rate_max_cost"], label[for="woocommerce_table_rate_min_cost"]').each(function( i, el ) {
var text = $(el).data( 'o_label' );
text = text.replace( '[item]', label_text );
$(el).text( text );
});
},
onShippingConditionChange: function() {
var selected = $( this ).val();
var $row = $( this ).closest('tr');

if ( selected == '' ) {
$row.find('input[name^="shipping_min"], input[name^="shipping_max"]').val( '' ).prop( 'disabled', true ).addClass( 'disabled' );
} else {
$row.find('input[name^="shipping_min"], input[name^="shipping_max"]').prop( 'disabled', false ).removeClass( 'disabled' );
}
},
onShippingAbortChange: function() {
var checked = $( this ).is( ':checked' );
var $row = $( this ).closest( 'tr' );

if ( checked ) {
$row.find('td.cost').hide();
$row.find('td.abort_reason').show();
$row.find('input[name^="shipping_per_item"], input[name^="shipping_cost_per_weight"], input[name^="shipping_cost_percent"], input[name^="shipping_cost"], input[name^="shipping_label"]').prop( 'disabled', true ).addClass( 'disabled' );
} else {
$row.find('td.cost').show();
$row.find('td.abort_reason').hide();
$row.find('input[name^="shipping_per_item"], input[name^="shipping_cost_per_weight"], input[name^="shipping_cost_percent"], input[name^="shipping_cost"], input[name^="shipping_label"]').prop( 'disabled', false ).removeClass( 'disabled' );
}

$( '#woocommerce_table_rate_calculation_type' ).change();
},
onAddRate: function( event ) {
event.preventDefault();
var target = $rates;
var size = target.find( '.table_rate' ).length;

target.append( wc_table_rate_rows_row_template( {
rate: {
rate_id: '',
rate_class: '',
rate_condition: '',
rate_min: '',
rate_max: '',
rate_priority: '',
rate_abort: '',
rate_abort_reason: '',
rate_cost: '',
rate_cost_per_item: '',
rate_cost_per_weight_unit: '',
rate_cost_percent: '',
rate_label: ''
},
index: size
} ) );

$( '#woocommerce_table_rate_calculation_type, select[name^="shipping_condition"], input[name^="shipping_abort["]', $rates_table ).change();
},
onRemoveRate: function( event ) {
event.preventDefault();
if ( confirm( data.i18n.delete_rates ) ) {
var rate_ids = [];

$rates.find( 'tr td.check-column input:checked' ).each( function( i, el ) {
var rate_id = $(el).closest( 'tr.table_rate' ).find( '.rate_id' ).val();
rate_ids.push( rate_id );
$(el).closest( 'tr.table_rate' ).addClass( 'deleting' );
});

var ajax_data = {
action: 'woocommerce_table_rate_delete',
rate_id: rate_ids,
security: data.delete_rates_nonce
};

$.post( ajaxurl, ajax_data, function(response) {
$( 'tr.deleting').fadeOut( '300', function() {
$( this ).remove();
} );
});
}
},
onDupeRate: function( event ) {
event.preventDefault();
if ( confirm( data.i18n.dupe_rates ) ) {

$rates.find( 'tr td.check-column input:checked' ).each( function( i, el ) {
var dupe = $(el).closest( 'tr' ).clone();
dupe.find( '.rate_id' ).val( '0' );
$rates.append( dupe );
});

wc_table_rate_rows.reindexRows();
}
},
reindexRows: function() {
var loop = 0;
$rates.find( 'tr' ).each( function( index, row ) {
$('input.text, input.checkbox, select.select, input[type=hidden]', row ).each( function( i, el ) {
var t = $(el);
t.attr( 'name', t.attr('name').replace(/\[([^[]*)\]/, "[" + loop + "]" ) );
});
loop++;
});
}
};

wc_table_rate_rows.init();

})( jQuery, woocommerce_shipping_table_rate_rows, wp, ajaxurl );
1 change: 1 addition & 0 deletions assets/js/table-rate-rows.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ca6a3a1

Please sign in to comment.