mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Hide Apple Pay gateway on ineligible devices
This commit is contained in:
parent
43d7e0788f
commit
3bb0496123
2 changed files with 44 additions and 12 deletions
|
@ -150,13 +150,31 @@ class ApplePayButton {
|
||||||
const idButton = this.buttonConfig.button.wrapper;
|
const idButton = this.buttonConfig.button.wrapper;
|
||||||
|
|
||||||
if ( ! this.isEligible ) {
|
if ( ! this.isEligible ) {
|
||||||
jQuery( '#' + idButton ).hide();
|
const hideContainers = [
|
||||||
jQuery( '#' + idMinicart ).hide();
|
// Payment button (Pay now, smart button block)
|
||||||
jQuery( '#express-payment-method-ppcp-applepay' ).hide();
|
`#${ idButton }`,
|
||||||
|
// Mini Cart button
|
||||||
|
`#${ idMinicart }`,
|
||||||
|
// Block Checkout: Express checkout button.
|
||||||
|
'#express-payment-method-ppcp-applepay',
|
||||||
|
];
|
||||||
|
|
||||||
|
hideContainers.forEach( ( selector ) => {
|
||||||
|
const elements = document.querySelectorAll( selector );
|
||||||
|
|
||||||
|
elements.forEach( ( element ) => {
|
||||||
|
element.style.display = 'none';
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Classic Checkout: Make the Apple Pay gateway visible.
|
||||||
|
document
|
||||||
|
.querySelectorAll( 'style#ppcp-hide-apple-pay' )
|
||||||
|
.forEach( ( el ) => el.remove() );
|
||||||
|
|
||||||
// Add click-handler to the button.
|
// Add click-handler to the button.
|
||||||
const setupButtonEvents = ( id ) => {
|
const setupButtonEvents = ( id ) => {
|
||||||
document
|
document
|
||||||
|
|
|
@ -953,6 +953,7 @@ class ApplePayButton implements ButtonInterface {
|
||||||
$render_placeholder,
|
$render_placeholder,
|
||||||
function () {
|
function () {
|
||||||
$this->applepay_button();
|
$this->applepay_button();
|
||||||
|
$this->hide_gateway_until_eligible();
|
||||||
},
|
},
|
||||||
21
|
21
|
||||||
);
|
);
|
||||||
|
@ -997,6 +998,19 @@ class ApplePayButton implements ButtonInterface {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs an inline CSS style that hides the Apple Pay gateway (on Classic Checkout).
|
||||||
|
* The style is removed by `ApplepayButton.js` once the eligibility of the payment method
|
||||||
|
* is confirmed.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function hide_gateway_until_eligible(): void {
|
||||||
|
?>
|
||||||
|
<style id="ppcp-hide-apple-pay">.wc_payment_method.payment_method_ppcp-applepay{display:none}</style>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueues the scripts.
|
* Enqueues the scripts.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue