Skip to content

Commit a2b6343

Browse files
authored
ECE: support checkout order notes (#4279)
* Add support for order notes when using express checkout * Add changelog and readme entries
1 parent 9d3fc2d commit a2b6343

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Fix - Prevents fatal errors for cases where we fail to load product details
2424
* Fix - Address an edge case with webhook URL comparisons
2525
* Fix - Show correct gateway name in non payments settings pages.
26+
* Update - Add support for customer order notes and express checkout
2627
* Dev - Minor fix to e2e setup code
2728
* Dev - Make PHP error log from Docker container available in docker/logs/php/error.log
2829

client/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { __ } from '@wordpress/i18n';
33
import apiFetch from '@wordpress/api-fetch';
44
import { applyFilters } from '@wordpress/hooks';
55
import {
6+
getCustomerNote,
67
getExpressCheckoutData,
78
getExpressCheckoutAjaxURL,
89
getRequiredFieldDataFromCheckoutForm,
@@ -610,6 +611,7 @@ export default class WCStripeAPI {
610611
expressCheckoutECECreateOrder( paymentData ) {
611612
return this.postToBlocksAPI( '/wc/store/v1/checkout', {
612613
...getRequiredFieldDataFromCheckoutForm( paymentData ),
614+
customer_note: getCustomerNote(),
613615
} );
614616
}
615617

client/express-checkout/utils/__tests__/normalize.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ describe( 'Express checkout normalization', () => {
178178
postcode: '10001',
179179
state: 'NY',
180180
},
181-
customer_note: undefined,
182181
extensions: {},
183182
payment_data: [
184183
{
@@ -272,7 +271,6 @@ describe( 'Express checkout normalization', () => {
272271
postcode: '',
273272
state: '',
274273
},
275-
customer_note: undefined,
276274
extensions: {},
277275
payment_data: [
278276
{
@@ -339,7 +337,6 @@ describe( 'Express checkout normalization', () => {
339337
postcode: '',
340338
state: '',
341339
},
342-
customer_note: undefined,
343340
extensions: {},
344341
payment_data: [
345342
{

client/express-checkout/utils/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,29 @@ export const getExpressCheckoutButtonStyleSettings = () => {
171171
};
172172
};
173173

174+
/**
175+
* Get the customer note from the checkout form.
176+
*
177+
* @return {string} The customer note.
178+
*/
179+
export const getCustomerNote = () => {
180+
const classicCheckoutOrderNotes = document.querySelector(
181+
'form.checkout textarea[name="order_comments"]'
182+
);
183+
if ( classicCheckoutOrderNotes ) {
184+
return classicCheckoutOrderNotes.value;
185+
}
186+
187+
const blockCheckoutOrderNotes = document.querySelector(
188+
'form.wc-block-checkout__form #order-notes textarea'
189+
);
190+
if ( blockCheckoutOrderNotes ) {
191+
return blockCheckoutOrderNotes.value;
192+
}
193+
194+
return '';
195+
};
196+
174197
export const getRequiredFieldDataFromCheckoutForm = ( data ) => {
175198
return getExpressCheckoutData( 'has_block' )
176199
? getRequiredFieldDataFromBlockCheckoutForm( data )

client/express-checkout/utils/normalize.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export const normalizeOrderData = ( {
7575
postcode: shipping?.address?.postal_code ?? '',
7676
method: [ event?.shippingRate?.id ?? null ],
7777
},
78-
customer_note: event?.order_comments,
7978
payment_method: 'stripe',
8079
payment_data: buildBlocksAPIPaymentData( {
8180
expressPaymentType: event?.expressPaymentType,

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
133133
* Fix - Prevents fatal errors for cases where we fail to load product details
134134
* Fix - Address an edge case with webhook URL comparisons
135135
* Fix - Show correct gateway name in non payments settings pages.
136+
* Update - Add support for customer order notes and express checkout
136137
* Dev - Minor fix to e2e setup code
137138
* Dev - Make PHP error log from Docker container available in docker/logs/php/error.log
138139

0 commit comments

Comments
 (0)