Skip to content

Commit 823c118

Browse files
authored
Auto-complete first and last name when using Link PM (#2457)
1 parent e477593 commit 823c118

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Tweak - Remove remaining traces of old Stripe settings.
77
* Add - Add Boleto expiration setting.
88
* Add - Declare incompatibility with HPOS.
9+
* Add - Auto-complete first and last name on checkout form when using Link payment method.
910

1011
= 6.8.0 - 2022-09-28 =
1112
* Fix - Minor adjustments for Custom Order Tables compatibility.

client/blocks/upe/fields.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const UPEField = ( {
8585
state: 'components-form-token-input-1',
8686
postal_code: 'shipping-postcode',
8787
country: 'components-form-token-input-0',
88+
first_name: 'shipping-first_name',
89+
last_name: 'shipping-last_name',
8890
};
8991
const billingAddressFields = {
9092
line1: 'billing-address_1',
@@ -93,6 +95,8 @@ const UPEField = ( {
9395
state: 'components-form-token-input-3',
9496
postal_code: 'billing-postcode',
9597
country: 'components-form-token-input-2',
98+
first_name: 'billing-first_name',
99+
last_name: 'billing-last_name',
96100
};
97101

98102
enableStripeLinkPaymentMethod( {

client/classic/upe/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ jQuery( function ( $ ) {
268268
state: 'shipping_state',
269269
postal_code: 'shipping_postcode',
270270
country: 'shipping_country',
271+
first_name: 'shipping_first_name',
272+
last_name: 'shipping_last_name',
271273
},
272274
billing_fields: {
273275
line1: 'billing_address_1',
@@ -276,6 +278,8 @@ jQuery( function ( $ ) {
276278
state: 'billing_state',
277279
postal_code: 'billing_postcode',
278280
country: 'billing_country',
281+
first_name: 'billing_first_name',
282+
last_name: 'billing_last_name',
279283
},
280284
} );
281285
}

client/stripe-link/index.js

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,75 @@ const enableStripeLinkPaymentMethod = ( options ) => {
5252
};
5353

5454
if ( options.complete_shipping() ) {
55+
const shippingNames = shippingAddress.name.split( / (.*)/s, 2 );
56+
shippingAddress.address.last_name = shippingNames[ 1 ] ?? '';
57+
shippingAddress.address.first_name = shippingNames[ 0 ];
58+
5559
fillWith( shippingAddress, options.shipping_fields.line1, 'line1' );
5660
fillWith( shippingAddress, options.shipping_fields.line2, 'line2' );
5761
fillWith( shippingAddress, options.shipping_fields.city, 'city' );
58-
fillWith( shippingAddress, options.shipping_fields.state, 'state' );
5962
fillWith(
6063
shippingAddress,
61-
options.shipping_fields.postal_code,
62-
'postal_code'
64+
options.shipping_fields.country,
65+
'country'
6366
);
6467
fillWith(
6568
shippingAddress,
66-
options.shipping_fields.country,
67-
'country'
69+
options.shipping_fields.first_name,
70+
'first_name'
71+
);
72+
fillWith(
73+
shippingAddress,
74+
options.shipping_fields.last_name,
75+
'last_name'
76+
);
77+
jQuery(
78+
'#billing_country, #billing_state, #shipping_country, #shipping_state'
79+
).trigger( 'change' );
80+
fillWith( shippingAddress, options.shipping_fields.state, 'state' );
81+
fillWith(
82+
shippingAddress,
83+
options.shipping_fields.postal_code,
84+
'postal_code'
6885
);
6986
}
7087

7188
if ( options.complete_billing() ) {
89+
const billingNames = billingAddress.name.split( / (.*)/s, 2 );
90+
billingAddress.address.last_name = billingNames[ 1 ] ?? '';
91+
billingAddress.address.first_name = billingNames[ 0 ];
92+
7293
fillWith( billingAddress, options.billing_fields.line1, 'line1' );
7394
fillWith( billingAddress, options.billing_fields.line2, 'line2' );
7495
fillWith( billingAddress, options.billing_fields.city, 'city' );
75-
fillWith( billingAddress, options.billing_fields.state, 'state' );
7696
fillWith(
7797
billingAddress,
78-
options.billing_fields.postal_code,
79-
'postal_code'
98+
options.billing_fields.country,
99+
'country'
80100
);
81101
fillWith(
82102
billingAddress,
83-
options.billing_fields.country,
84-
'country'
103+
options.billing_fields.first_name,
104+
'first_name'
105+
);
106+
fillWith(
107+
billingAddress,
108+
options.billing_fields.last_name,
109+
'last_name'
110+
);
111+
jQuery(
112+
'#billing_country, #billing_state, #shipping_country, #shipping_state'
113+
).trigger( 'change' );
114+
fillWith( billingAddress, options.billing_fields.state, 'state' );
115+
fillWith(
116+
billingAddress,
117+
options.billing_fields.postal_code,
118+
'postal_code'
85119
);
86120
}
87-
jQuery( 'select' ).trigger( 'change' );
121+
jQuery(
122+
'#billing_country, #billing_state, #shipping_country, #shipping_state'
123+
).trigger( 'change' );
88124
} );
89125
};
90126

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 7.0.0 - 2022-xx-xx =
132+
* Add - Auto-complete first and last name on checkout form when using Link payment method.
132133

133134
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)