-
Notifications
You must be signed in to change notification settings - Fork 72
Add support for WooCommerce Deposits when using Apple Pay and Google Pay #7910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
7627f38
52293a3
21cdddf
f55654e
fedb13b
18af61d
a9b2903
1f13e7e
4ce48d4
e37202f
9014f3c
0899435
63afd86
80c03fe
128de05
36f9e95
8ba894b
eff996e
5f91139
a933580
980c374
9c54d6b
8cb9622
90a9c25
4f98928
804ebed
369509e
aa580db
1663d76
5d8c4ae
fcfe4f5
91ec6c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
Added support for WooCommerce Deposits when using Apple Pay and Google Pay |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { doAction } from '@wordpress/hooks'; | ||
import { applyFilters, doAction } from '@wordpress/hooks'; | ||
import { debounce } from 'lodash'; | ||
/** | ||
* Internal dependencies | ||
|
@@ -189,8 +189,19 @@ jQuery( ( $ ) => { | |
|
||
// Add addons data to the POST body | ||
const formData = $( 'form.cart' ).serializeArray(); | ||
let allowedFieldNames = applyFilters( | ||
'wcpayPaymentRequestAllowedFieldNames', | ||
[] | ||
); | ||
// Ensure allowedFieldNames is an array. | ||
if ( ! Array.isArray( allowedFieldNames ) ) { | ||
allowedFieldNames = [ allowedFieldNames ]; | ||
} | ||
$.each( formData, ( i, field ) => { | ||
if ( /^addon-/.test( field.name ) ) { | ||
if ( | ||
allowedFieldNames.includes( field.name ) || | ||
/^(addon-|wc_)/.test( field.name ) | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking and nice-to-have (or a good candidate for a separate small issue): It'd be beneficial to streamline this |
||
if ( /\[\]$/.test( field.name ) ) { | ||
const fieldName = field.name.substring( | ||
0, | ||
|
@@ -302,13 +313,22 @@ jQuery( ( $ ) => { | |
0 | ||
); | ||
|
||
// WC Deposits Support. | ||
const depositObject = {}; | ||
if ( $( 'input[name=wc_deposit_option]' ).length ) { | ||
depositObject.wc_deposit_option = $( | ||
'input[name=wc_deposit_option]:checked' | ||
).val(); | ||
} | ||
|
||
const data = { | ||
product_id: productId, | ||
qty: $( '.quantity .qty' ).val(), | ||
attributes: $( '.variations_form' ).length | ||
? wcpayPaymentRequest.getAttributes().data | ||
: [], | ||
addon_value: addonValue, | ||
...depositObject, | ||
}; | ||
|
||
return api.paymentRequestGetSelectedProductData( data ); | ||
|
@@ -429,6 +449,14 @@ jQuery( ( $ ) => { | |
wcpayPaymentRequest.addToCart(); | ||
} ); | ||
|
||
// WooCommerce Deposits support. | ||
// Trigger the "woocommerce_variation_has_changed" event when the deposit option is changed. | ||
$( 'input[name=wc_deposit_option]' ).on( 'change', () => { | ||
gpressutto5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$( 'form:has(input[name=wc_deposit_option])' ).trigger( | ||
gpressutto5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'woocommerce_variation_has_changed' | ||
); | ||
} ); | ||
|
||
$( document.body ).on( 'woocommerce_variation_has_changed', () => { | ||
wcpayPaymentRequest.blockPaymentRequestButton(); | ||
|
||
|
gpressutto5 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.