mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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;
|
||||
|
||||
if ( ! this.isEligible ) {
|
||||
jQuery( '#' + idButton ).hide();
|
||||
jQuery( '#' + idMinicart ).hide();
|
||||
jQuery( '#express-payment-method-ppcp-applepay' ).hide();
|
||||
const hideContainers = [
|
||||
// Payment button (Pay now, smart button block)
|
||||
`#${ 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;
|
||||
}
|
||||
|
||||
// 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.
|
||||
const setupButtonEvents = ( id ) => {
|
||||
document
|
||||
|
|
|
@ -443,15 +443,15 @@ class ApplePayButton implements ButtonInterface {
|
|||
)
|
||||
);
|
||||
} else {
|
||||
add_filter(
|
||||
'woocommerce_payment_successful_result',
|
||||
function ( array $result ) use ( $cart, $cart_item_key ) : array {
|
||||
$this->clear_current_cart( $cart, $cart_item_key );
|
||||
$this->reload_cart( $cart );
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
}
|
||||
add_filter(
|
||||
'woocommerce_payment_successful_result',
|
||||
function ( array $result ) use ( $cart, $cart_item_key ) : array {
|
||||
$this->clear_current_cart( $cart, $cart_item_key );
|
||||
$this->reload_cart( $cart );
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
WC()->checkout()->process_checkout();
|
||||
|
@ -953,6 +953,7 @@ class ApplePayButton implements ButtonInterface {
|
|||
$render_placeholder,
|
||||
function () {
|
||||
$this->applepay_button();
|
||||
$this->hide_gateway_until_eligible();
|
||||
},
|
||||
21
|
||||
);
|
||||
|
@ -997,6 +998,19 @@ class ApplePayButton implements ButtonInterface {
|
|||
<?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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue