Skip to content

Commit b5dd443

Browse files
author
Woo
committed
Updates to 2.9.4
1 parent 39fe842 commit b5dd443

19 files changed

+637
-237
lines changed

assets/js/admin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
data._billing_country = $( '#_billing_country' ).val();
99
data._shipping_country = $( '#_shipping_country' ).val();
1010
data._billing_postcode = $( '#_billing_postcode' ).val();
11+
data._shipping_postcode = $( '#_shipping_postcode' ).val();
1112
}
1213
}
1314
);

assets/js/admin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/eu-vat.js

Lines changed: 112 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,144 @@
1-
jQuery(function(){
1+
/* global wc_eu_vat_params, wc_address_i18n_params */
2+
/* eslint-disable camelcase */
3+
jQuery( function () {
4+
const useShippingCountry = wc_eu_vat_params.use_shipping_country;
5+
const billingVatNumber = '#woocommerce_eu_vat_number_field';
6+
const shippingVatNumber = '#woocommerce_eu_vat_number_shipping_field';
7+
28
function field_is_required( field, is_required ) {
39
if ( is_required ) {
410
field.find( 'label .optional' ).remove();
511
field.addClass( 'validate-required' );
612

713
if ( field.find( 'label .required' ).length === 0 ) {
8-
field.find( 'label' ).append(
9-
'&nbsp;<abbr class="required" title="' +
10-
wc_address_i18n_params.i18n_required_text +
11-
'">*</abbr>'
12-
);
14+
field
15+
.find( 'label' )
16+
.append(
17+
'<abbr class="required" title="' +
18+
wc_address_i18n_params.i18n_required_text +
19+
'">*</abbr>'
20+
);
1321
}
1422
} else {
1523
field.find( 'label .required' ).remove();
16-
field.removeClass( 'validate-required woocommerce-invalid woocommerce-invalid-required-field' );
24+
field.removeClass(
25+
'validate-required woocommerce-invalid woocommerce-invalid-required-field'
26+
);
1727

1828
if ( field.find( 'label .optional' ).length === 0 ) {
19-
field.find( 'label' ).append( '&nbsp;<span class="optional">(' + wc_address_i18n_params.i18n_optional_text + ')</span>' );
29+
field
30+
.find( 'label' )
31+
.append(
32+
'<span class="optional">(' +
33+
wc_address_i18n_params.i18n_optional_text +
34+
')</span>'
35+
);
2036
}
2137
}
2238
}
2339

24-
jQuery( 'form.checkout, form#order_review').on( 'change', '#billing_country', function() {
25-
var country = jQuery( '#billing_country' ).val();
26-
var check_countries = wc_eu_vat_params.eu_countries;
27-
var b2b_enabled = wc_eu_vat_params.b2b_required;
40+
// Handle change billing/shipping country.
41+
function changeCountry() {
42+
const billingCountry = jQuery( '#billing_country' ).val();
43+
const shippingCountry = jQuery( '#shipping_country' ).val();
44+
const shipToDifferent = jQuery(
45+
'#ship-to-different-address-checkbox'
46+
).is( ':checked' );
47+
const validateShippingCountry =
48+
useShippingCountry && shippingCountry && shipToDifferent;
49+
const country = validateShippingCountry
50+
? shippingCountry
51+
: billingCountry;
52+
const check_countries = wc_eu_vat_params.eu_countries;
53+
const b2b_enabled = wc_eu_vat_params.b2b_required;
54+
55+
const vat_number_field = validateShippingCountry
56+
? jQuery( shippingVatNumber )
57+
: jQuery( billingVatNumber );
2858

29-
field_is_required( jQuery( '#woocommerce_eu_vat_number_field' ), false );
59+
field_is_required( vat_number_field, false );
3060

3161
if ( country && jQuery.inArray( country, check_countries ) >= 0 ) {
32-
jQuery( '#woocommerce_eu_vat_number_field' ).fadeIn();
33-
if ( 'yes' === b2b_enabled ) {
34-
field_is_required( jQuery( '#woocommerce_eu_vat_number_field' ), true );
62+
vat_number_field.fadeIn();
63+
if ( b2b_enabled === 'yes' ) {
64+
field_is_required( vat_number_field, true );
3565
}
3666
} else {
37-
jQuery( '#woocommerce_eu_vat_number_field' ).fadeOut();
67+
vat_number_field.fadeOut();
3868
}
39-
});
69+
}
70+
71+
jQuery( 'form.checkout, form#order_review' ).on(
72+
'change',
73+
'#billing_country',
74+
changeCountry
75+
);
4076
jQuery( '#billing_country' ).trigger( 'change' );
4177

78+
if ( useShippingCountry ) {
79+
jQuery( 'form.checkout, form#order_review' ).on(
80+
'change',
81+
'#shipping_country',
82+
changeCountry
83+
);
84+
jQuery( '#shipping_country' ).trigger( 'change' );
85+
}
86+
87+
// Trigger country change on ship to different address checkbox change.
88+
jQuery( 'form.checkout, form#order_review' ).on(
89+
'change',
90+
'#ship-to-different-address-checkbox',
91+
function () {
92+
if ( ! useShippingCountry ) {
93+
return;
94+
}
95+
96+
const isChecked = jQuery(
97+
'#ship-to-different-address-checkbox'
98+
).is( ':checked' );
99+
100+
if ( isChecked ) {
101+
jQuery( billingVatNumber ).fadeOut();
102+
jQuery( '#shipping_country' ).trigger( 'change' );
103+
} else {
104+
jQuery( shippingVatNumber ).fadeOut();
105+
jQuery( '#billing_country' ).trigger( 'change' );
106+
}
107+
}
108+
);
109+
jQuery( '#ship-to-different-address-checkbox' ).trigger( 'change' );
110+
42111
/* Validate EU VAT Number field only on change event */
43-
jQuery( 'form.checkout, form#order_review' ).on( 'change', '#woocommerce_eu_vat_number', function() {
44-
jQuery( 'body' ).trigger( 'update_checkout' );
45-
} );
112+
jQuery( 'form.checkout, form#order_review' ).on(
113+
'change',
114+
billingVatNumber,
115+
function () {
116+
jQuery( 'body' ).trigger( 'update_checkout' );
117+
}
118+
);
119+
120+
if ( useShippingCountry ) {
121+
jQuery( 'form.checkout, form#order_review' ).on(
122+
'change',
123+
shippingVatNumber,
124+
function () {
125+
jQuery( 'body' ).trigger( 'update_checkout' );
126+
}
127+
);
128+
}
46129

47130
/**
48131
* Handles checkout field UI when VAT field validation fails.
49132
*/
50133
jQuery( document.body ).on( 'updated_checkout', function( e, data ) {
51-
$vat_field = jQuery( '#woocommerce_eu_vat_number' );
134+
const shippingCountry = jQuery( '#shipping_country' ).val();
135+
const shipToDifferent = jQuery(
136+
'#ship-to-different-address-checkbox'
137+
).is( ':checked' );
138+
const $vat_field =
139+
useShippingCountry && shippingCountry && shipToDifferent
140+
? jQuery( shippingVatNumber )
141+
: jQuery( billingVatNumber );
52142

53143
if ( ! $vat_field.is( ':visible' ) ) {
54144
return;

assets/js/eu-vat.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/frontend.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wc-blocks-checkout', 'wc-settings', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e3d7d07c67aecd20c69de0d94c963346');
1+
<?php return array('dependencies' => array('wc-blocks-checkout', 'wc-settings', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '16638e3a3498458e80c2f3e08daa4d3e');

0 commit comments

Comments
 (0)