';
$( errors ).each( function( index, value ) {
error_html = error_html + '
' + value + '
';
} );
error_html = error_html + '
';
$( 'table.wc-shipping-zone-methods' ).before( error_html );
},
highlightOnFocus: function( query ) {
const inputs = $( query );
inputs.focus( function() {
$( this ).select();
} );
},
onAddShippingMethod: function( event ) {
event.preventDefault();
$( this ).WCBackboneModal({
template : 'wc-modal-add-shipping-method',
variable : {
zone_id : data.zone_id
}
});
$( '.wc-shipping-zone-method-selector select' ).trigger( 'change' );
$('.wc-shipping-zone-method-input input').change( function() {
const selected = $('.wc-shipping-zone-method-input input:checked');
const id = selected.attr( 'id' );
const description = $( `#${ id }-description` );
const descriptions = $( '.wc-shipping-zone-method-input-help-text' );
descriptions.css( 'display', 'none' );
description.css( 'display', 'block' );
});
},
/**
* The settings HTML is controlled and built by the settings api, so in order to refactor the
* markup, it needs to be manipulated here.
*/
reformatSettingsHTML: function( html ) {
const formattingFunctions = [
this.replaceHTMLTables,
this.moveAdvancedCostsHelpTip,
this.moveHTMLHelpTips,
this.addCurrencySymbol
];
return formattingFunctions.reduce( ( formattedHTML, fn ) => {
return fn( formattedHTML );
}, html );
},
moveAdvancedCostsHelpTip: function( html ) {
const htmlContent = $( html );
const advancedCostsHelpTip = htmlContent.find( '#wc-shipping-advanced-costs-help-text' );
advancedCostsHelpTip.addClass( 'wc-shipping-zone-method-fields-help-text' );
const input = htmlContent.find( '#woocommerce_flat_rate_cost' );
const fieldset = input.closest( 'fieldset' );
advancedCostsHelpTip.appendTo( fieldset );
return htmlContent.prop( 'outerHTML' );
},
addCurrencySymbol: function( html ) {
if ( ! window.wc.wcSettings.CURRENCY || ! window.wc.currency.localiseMonetaryValue ) {
return html;
}
const htmlContent = $( html );
const priceInputs = htmlContent.find( '.wc-shipping-modal-price' );
const config = window.wc.wcSettings.CURRENCY;
const { symbol, symbolPosition } = config;
priceInputs.addClass( `wc-shipping-currency-size-${ symbol.length }` );
priceInputs.addClass( `wc-shipping-currency-position-${ symbolPosition }` );
priceInputs.before(
`