This commit is contained in:
Mike Jolley 2015-04-27 13:56:30 +01:00
parent 030ac9c50e
commit cb8332cffc
4 changed files with 76 additions and 12 deletions

View File

@ -25,7 +25,7 @@ jQuery(function( $ ) {
}
}).change();
$('input[name="enable_shipping"]').change(function(){
$('input[name="woocommerce_calc_shipping"]').change(function(){
if ( $(this).is( ':checked' ) ) {
$(':input[name="shipping_cost_domestic"]').closest('tr').show();
$(':input[name="shipping_cost_international"]').closest('tr').show();

View File

@ -1 +1 @@
jQuery(function(a){var b=a.parseJSON(wc_setup_params.locale_info);a('select[name="store_location"]').change(function(){var c=a(this).val(),d=c.split(":")[0],e=b[d],f=["thousand_sep","decimal_sep","num_decimals","currency_pos"];e?a.each(e,function(b,c){a(':input[name="'+b+'"]').val(c).change(),-1!=a.inArray(b,f)&&a(':input[name="'+b+'"]').closest("tr").hide()}):(a(':input[name="currency_code"]').val("").change(),a(':input[name="currency_pos"]').val("left").change().closest("tr").show(),a(':input[name="thousand_sep"]').val(",").change().closest("tr").show(),a(':input[name="decimal_sep"]').val(".").change().closest("tr").show(),a(':input[name="num_decimals"]').val("2").change().closest("tr").show())}).change(),a('input[name="enable_shipping"]').change(function(){a(this).is(":checked")?(a(':input[name="shipping_cost_domestic"]').closest("tr").show(),a(':input[name="shipping_cost_international"]').closest("tr").show()):(a(':input[name="shipping_cost_domestic"]').closest("tr").hide(),a(':input[name="shipping_cost_international"]').closest("tr").hide())}).change(),a('input[name="woocommerce_calc_taxes"]').change(function(){a(this).is(":checked")?(a(':input[name="woocommerce_prices_include_tax"]').closest("tr").show(),a("tr.tax-rates").show()):(a(':input[name="woocommerce_prices_include_tax"]').closest("tr").hide(),a("tr.tax-rates").hide())}).change()});
jQuery(function(a){var b=a.parseJSON(wc_setup_params.locale_info);a('select[name="store_location"]').change(function(){var c=a(this).val(),d=c.split(":")[0],e=b[d],f=["thousand_sep","decimal_sep","num_decimals","currency_pos"];e?a.each(e,function(b,c){a(':input[name="'+b+'"]').val(c).change(),-1!=a.inArray(b,f)&&a(':input[name="'+b+'"]').closest("tr").hide()}):(a(':input[name="currency_code"]').val("").change(),a(':input[name="currency_pos"]').val("left").change().closest("tr").show(),a(':input[name="thousand_sep"]').val(",").change().closest("tr").show(),a(':input[name="decimal_sep"]').val(".").change().closest("tr").show(),a(':input[name="num_decimals"]').val("2").change().closest("tr").show())}).change(),a('input[name="woocommerce_calc_shipping"]').change(function(){a(this).is(":checked")?(a(':input[name="shipping_cost_domestic"]').closest("tr").show(),a(':input[name="shipping_cost_international"]').closest("tr").show()):(a(':input[name="shipping_cost_domestic"]').closest("tr").hide(),a(':input[name="shipping_cost_international"]').closest("tr").hide())}).change(),a('input[name="woocommerce_calc_taxes"]').change(function(){a(this).is(":checked")?(a(':input[name="woocommerce_prices_include_tax"]').closest("tr").show(),a("tr.tax-rates").show()):(a(':input[name="woocommerce_prices_include_tax"]').closest("tr").hide(),a("tr.tax-rates").hide())}).change()});

View File

@ -60,7 +60,7 @@ class WC_Admin_Welcome {
'shipping_taxes' => array(
'name' => __( 'Shipping & Tax', 'woocommerce' ),
'view' => array( $this, 'wc_setup_shipping_taxes' ),
'handler' => ''
'handler' => array( $this, 'wc_setup_shipping_taxes_save' ),
),
'next_steps' => array(
'name' => __( 'Ready!', 'woocommerce' ),
@ -389,22 +389,22 @@ class WC_Admin_Welcome {
</td>
</tr>
<tr>
<th scope="row"><label for="enable_shipping"><?php _e( 'Will you be shipping products?', 'woocommerce' ); ?></label></th>
<th scope="row"><label for="woocommerce_calc_shipping"><?php _e( 'Will you be shipping products?', 'woocommerce' ); ?></label></th>
<td>
<input type="checkbox" id="enable_shipping" name="enable_shipping" class="input-checkbox" value="1" />
<label for="enable_shipping"><?php _e( 'Yes, I will be shipping physical goods to customers', 'woocommerce' ); ?></label>
<input type="checkbox" id="woocommerce_calc_shipping" name="woocommerce_calc_shipping" class="input-checkbox" value="1" />
<label for="woocommerce_calc_shipping"><?php _e( 'Yes, I will be shipping physical goods to customers', 'woocommerce' ); ?></label>
</td>
</tr>
<tr>
<th scope="row"><label for="shipping_cost_domestic"><?php _e( 'How much do you charge to ship products <strong>domestically</strong>?', 'woocommerce' ); ?></label></th>
<td>
<?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_domestic" name="shipping_cost_domestic" size="5" value="" />
<?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_domestic" name="shipping_cost_domestic" size="5" value="" /> <?php _e( 'per order, and', 'woocommerce' ); ?> <?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_domestic_item" name="shipping_cost_domestic_item" size="5" value="" /> <?php _e( 'per item', 'woocommerce' ); ?>
</td>
</tr>
<tr>
<th scope="row"><label for="shipping_cost_international"><?php _e( 'How much do you charge to ship products <strong>internationally</strong>?', 'woocommerce' ); ?></label></th>
<td>
<?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_international" name="shipping_cost_international" size="5" value="" />
<?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_international" name="shipping_cost_international" size="5" value="" /> <?php _e( 'per order, and', 'woocommerce' ); ?> <?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="shipping_cost_international_item" name="shipping_cost_international_item" size="5" value="" /> <?php _e( 'per item', 'woocommerce' ); ?>
</td>
</tr>
<tr class="section_title">
@ -423,7 +423,13 @@ class WC_Admin_Welcome {
<th scope="row"><label for="woocommerce_prices_include_tax"><?php _e( 'Will you enter product prices including taxes?', 'woocommerce' ); ?></label></th>
<td>
<label><input type="radio" checked id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="yes" /> <?php _e( 'Yes, I will enter prices inclusive of tax', 'woocommerce' ); ?></label><br/>
<label><input type="radio" id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="yes" /> <?php _e( 'No, I will enter prices exclusive of tax', 'woocommerce' ); ?></label>
<label><input type="radio" id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="no" /> <?php _e( 'No, I will enter prices exclusive of tax', 'woocommerce' ); ?></label>
</td>
</tr>
<tr>
<th scope="row"><label for="woocommerce_prices_include_tax"><?php _e( 'Import Tax Rates', 'woocommerce' ); ?></label></th>
<td>
<label><input type="radio" checked id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="yes" /> <?php _e( 'Yes, import tax rates', 'woocommerce' ); ?></label>
</td>
</tr>
<tr class="section_title tax-rates">
@ -464,6 +470,53 @@ class WC_Admin_Welcome {
<?php
}
/**
* Save shipping and tax options
*/
public function wc_setup_shipping_taxes_save() {
$woocommerce_calc_shipping = isset( $_POST['woocommerce_calc_shipping'] ) ? 'yes' : 'no';
$woocommerce_calc_taxes = isset( $_POST['woocommerce_calc_taxes'] ) ? 'yes' : 'no';
update_option( 'woocommerce_calc_shipping', $woocommerce_calc_shipping );
update_option( 'woocommerce_calc_taxes', $woocommerce_calc_taxes );
update_option( 'woocommerce_prices_include_tax', sanitize_text_field( $_POST['woocommerce_prices_include_tax'] ) );
if ( 'yes' === $woocommerce_calc_shipping && ! empty( $_POST['shipping_cost_domestic'] ) ) {
// Delete existing settings if they exist
delete_option( 'woocommerce_flat_rates' );
delete_option( 'woocommerce_flat_rate_settings' );
// Init rate and settings
$shipping_method = new WC_Shipping_Flat_Rate();
$shipping_method->settings['enabled'] = 'yes';
$shipping_method->settings['type'] = 'item';
$shipping_method->settings['cost_per_order'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_domestic'] ) );
$shipping_method->settings['cost'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_domestic_item'] ) );
$shipping_method->settings['fee'] = '';
update_option( $shipping_method->plugin_id . $shipping_method->id . '_settings', $shipping_method->settings );
}
if ( 'yes' === $woocommerce_calc_shipping && ! empty( $_POST['shipping_cost_international'] ) ) {
// Delete existing settings if they exist
delete_option( 'woocommerce_international_delivery_flat_rates' );
delete_option( 'woocommerce_international_delivery_settings' );
// Init rate and settings
$shipping_method = new WC_Shipping_International_Delivery();
$shipping_method->settings['enabled'] = 'yes';
$shipping_method->settings['type'] = 'item';
$shipping_method->settings['cost_per_order'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_international'] ) );
$shipping_method->settings['cost'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_international_item'] ) );
$shipping_method->settings['fee'] = '';
update_option( $shipping_method->plugin_id . $shipping_method->id . '_settings', $shipping_method->settings );
}
wp_redirect( $this->get_next_step_link() );
exit;
}
/**
* Final step
*/

View File

@ -93,6 +93,14 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
'none' => _x( 'None', 'Tax status', 'woocommerce' )
)
),
'cost_per_order' => array(
'title' => __( 'Cost per order', 'woocommerce' ),
'type' => 'price',
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Enter a cost (excluding tax) per order, e.g. 5.00. Default is 0.', 'woocommerce' ),
'default' => '',
'desc_tip' => true
),
'type' => array(
'title' => __( 'Cost Added...', 'woocommerce' ),
'type' => 'select',
@ -171,7 +179,8 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
* @return void
*/
public function calculate_shipping( $package = array() ) {
$this->rates = array();
$this->rates = array();
$cost_per_order = ! empty( $this->cost_per_order ) ? $this->cost_per_order : 0;
if ( 'order' === $this->type ) {
@ -180,7 +189,7 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $shipping_total ? $shipping_total : 0,
'cost' => $cost_per_order + ( $shipping_total ? $shipping_total : 0 ),
);
} elseif ( 'class' === $this->type ) {
@ -190,7 +199,7 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $shipping_total ? $shipping_total : 0,
'cost' => $cost_per_order + ( $shipping_total ? $shipping_total : 0 ),
);
} elseif ( 'item' === $this->type ) {
@ -201,6 +210,8 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
$costs = array();
}
$costs['order'] = $cost_per_order;
$rate = array(
'id' => $this->id,
'label' => $this->title,