Setup wizard: add method-specific settings and descriptions to shipping step.

This commit is contained in:
Jeff Stieler 2017-09-08 21:53:34 -06:00
parent 58a289dc20
commit 5642868436
3 changed files with 44 additions and 9 deletions

View File

@ -104,4 +104,17 @@ jQuery( function( $ ) {
.slideToggle()
.css( 'display', 'flex' );
} );
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-select', function( e ) {
var $zone = $( this );
var selected_method = e.target.value;
var $descriptions = $zone.find( '.shipping-method-description' );
$descriptions.find( 'p' ).hide();
$descriptions.find( 'p.' + selected_method ).show();
var $settings = $zone.find( '.shipping-method-settings' );
$settings.find( 'div' ).hide();
$settings.find( 'div.' + selected_method ).show();
} );
} );

View File

@ -1 +1 @@
jQuery(function(e){var t=e.parseJSON(wc_setup_params.locale_info);e('select[name="store_location"]').change(function(){var a=e(this).val().split(":"),c=a[0],s=a[1]||!1,i=t[c],n=["thousand_sep","decimal_sep","num_decimals","currency_pos"];if(i){if(e.each(i,function(t,a){e(':input[name="'+t+'"]').val(a).change(),-1!==e.inArray(t,n)&&e(':input[name="'+t+'"]').closest("tr").hide()}),!e.isArray(i.tax_rates)){var r=[];if(s&&i.tax_rates[s]?r=r.concat(i.tax_rates[s]):i.tax_rates[""]&&(r=r.concat(i.tax_rates[""])),(r=r.concat(i.tax_rates["*"]||[])).length){var o=e("table.tax-rates tbody").empty();e.each(r,function(t,a){e("<tr>",{html:[e("<td>",{"class":"readonly",text:a.country||""}),e("<td>",{"class":"readonly",text:a.state||"*"}),e("<td>",{"class":"readonly",text:a.rate||""}),e("<td>",{"class":"readonly",text:a.name||""})]}).appendTo(o)}),e(".tax-rates").show()}else e(".tax-rates").hide()}}else e(':input[name="currency_pos"]').closest("tr").show(),e(':input[name="thousand_sep"]').closest("tr").show(),e(':input[name="decimal_sep"]').closest("tr").show(),e(':input[name="num_decimals"]').closest("tr").show(),e(".tax-rates").hide()}).change(),e('input[name="woocommerce_calc_taxes"]').change(function(){e(this).is(":checked")?(e(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").show(),e("tr.tax-rates").show()):(e(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").hide(),e("tr.tax-rates").hide())}).change(),e(".button-next").on("click",function(){var t=e(this).parents("form").get(0);return"function"==typeof t.checkValidity&&t.checkValidity()&&e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"):e(this).closest(".wc-wizard-service-toggle").addClass("disabled")}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(t){t.stopPropagation();var a=e(this).find(".wc-wizard-service-toggle input");a.prop("checked",!a.prop("checked")).change()}),e(".wc-wizard-services-list-toggle").on("change",".wc-wizard-service-enable input",function(){e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")})});
jQuery(function(e){var t=e.parseJSON(wc_setup_params.locale_info);e('select[name="store_location"]').change(function(){var a=e(this).val().split(":"),s=a[0],c=a[1]||!1,i=t[s],n=["thousand_sep","decimal_sep","num_decimals","currency_pos"];if(i){if(e.each(i,function(t,a){e(':input[name="'+t+'"]').val(a).change(),-1!==e.inArray(t,n)&&e(':input[name="'+t+'"]').closest("tr").hide()}),!e.isArray(i.tax_rates)){var r=[];if(c&&i.tax_rates[c]?r=r.concat(i.tax_rates[c]):i.tax_rates[""]&&(r=r.concat(i.tax_rates[""])),(r=r.concat(i.tax_rates["*"]||[])).length){var o=e("table.tax-rates tbody").empty();e.each(r,function(t,a){e("<tr>",{html:[e("<td>",{"class":"readonly",text:a.country||""}),e("<td>",{"class":"readonly",text:a.state||"*"}),e("<td>",{"class":"readonly",text:a.rate||""}),e("<td>",{"class":"readonly",text:a.name||""})]}).appendTo(o)}),e(".tax-rates").show()}else e(".tax-rates").hide()}}else e(':input[name="currency_pos"]').closest("tr").show(),e(':input[name="thousand_sep"]').closest("tr").show(),e(':input[name="decimal_sep"]').closest("tr").show(),e(':input[name="num_decimals"]').closest("tr").show(),e(".tax-rates").hide()}).change(),e('input[name="woocommerce_calc_taxes"]').change(function(){e(this).is(":checked")?(e(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").show(),e("tr.tax-rates").show()):(e(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").hide(),e("tr.tax-rates").hide())}).change(),e(".button-next").on("click",function(){var t=e(this).parents("form").get(0);return"function"==typeof t.checkValidity&&t.checkValidity()&&e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"):e(this).closest(".wc-wizard-service-toggle").addClass("disabled")}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(t){t.stopPropagation();var a=e(this).find(".wc-wizard-service-toggle input");a.prop("checked",!a.prop("checked")).change()}),e(".wc-wizard-services-list-toggle").on("change",".wc-wizard-service-enable input",function(){e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select",function(t){var a=e(this),s=t.target.value,c=a.find(".shipping-method-description");c.find("p").hide(),c.find("p."+s).show();var i=a.find(".shipping-method-settings");i.find("div").hide(),i.find("div."+s).show()})});

View File

@ -524,22 +524,44 @@ class WC_Admin_Setup_Wizard {
* @param sting $zone_type
*/
protected function shipping_method_selection_form( $country_code, $zone_type = 'domestic' ) {
$input_name = "shipping_method_{$zone_type}";
$input_name = "shipping_method_{$zone_type}";
$flat_rate_input = "{$zone_type}_flat_rate";
$live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code );
$selected = $live_rate_carrier ? 'live_rates' : 'flat_rate';
?>
<div>
<div class="wc-wizard-shipping-method-select">
<select id="<?php echo esc_attr( $input_name ); ?>" name="<?php echo esc_attr( $input_name ); ?>" class="wc-enhanced-select">
<?php if ( $this->get_wcs_shipping_carrier( $country_code ) ) : ?>
<option value="live_rates" selected="selected">
<?php if ( $live_rate_carrier ) : ?>
<option value="live_rates" <?php selected( $selected, 'live_rates' ); ?>>
<?php esc_html_e( 'Live Rates', 'woocommerce' ); ?>
</option>
<?php endif; ?>
<option value="free_shipping">
<?php esc_html_e( 'Free Shipping', 'woocommerce' ); ?>
</option>
<option value="flat_rate">
<option value="flat_rate" <?php selected( $selected, 'flat_rate' ); ?>>
<?php esc_html_e( 'Flat Rate', 'woocommerce' ); ?>
</option>
<option value="free_shipping" <?php selected( $selected, 'free_shipping' ); ?>>
<?php esc_html_e( 'Free Shipping', 'woocommerce' ); ?>
</option>
</select>
<div class="shipping-method-description">
<p class="live_rates" <?php if ( 'live_rates' !== $selected ) echo 'style="display:none"'; ?>>
<?php esc_html_e( 'Shipping rates updated in realtime. Powered by Jetpack.', 'woocommerce' ); ?>
</p>
<p class="free_shipping" <?php if ( 'free_shipping' !== $selected ) echo 'style="display:none"'; ?>>
<?php esc_html_e( "Don't charge for shipping.", 'woocommerce' ); ?>
</p>
<p class="flat_rate">
<?php esc_html_e( 'Set a fixed price to cover shipping costs.', 'woocommerce' ); ?>
</p>
</div>
<div class="shipping-method-settings">
<div class="flat_rate" <?php if ( 'flat_rate' !== $selected ) echo 'style="display:none"'; ?>>
<input type="text" id="<?php echo esc_attr( $flat_rate_input ); ?>" name="<?php echo esc_attr( $flat_rate_input ); ?>" />
<p class="description">
<?php esc_html_e( 'What would you like to charge for flat rate shipping?', 'woocommerce' ); ?>
</p>
</div>
</div>
</div>
<?php
}