FREE EXPRESS SHIPPING Within Australia When You Spend $100 Or More FREE EXPRESS SHIPPING Within Australia When You Spend $100 Or More FREE EXPRESS SHIPPING Within Australia When You Spend $100 Or More
jQuery(document).ready(function($) {
// Function to re-style and initialize the Google Pay / Apple Pay buttons
function initializePaymentButtons() {
// Check if Stripe.js is loaded
if (typeof Stripe === 'undefined') return;
var stripe = Stripe('[<]?php echo esc_js(get_option( "woocommerce_stripe_settings_publishable_key" )); ?[>]'); // Get Stripekey
var elements = stripe.elements();
var paymentRequest = stripe.paymentRequest({
country: 'US', // Modify for your region
currency: 'usd', // Modify for your currency
total: {
label: 'Total',
amount: [ < ]?php echo WC()-[ > ]cart-[ > ]total; ?[ > ], // Get cart total
},
requestPayerName: true,
requestPayerEmail: true,
});
var prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
});
// Check if Payment Request API can be used
paymentRequest.canMakePayment().then(function(result) {
if (result) {
prButton.mount('#payment-request-button');
} else {
$('#payment-request-button').hide(); // Hide button if not supported
}
});
}
// Initialize the buttons when the page loads
initializePaymentButtons();
// Reinitialize buttons when the cart is updated
$(document.body).on('added_to_cart updated_cart', function() {
initializePaymentButtons(); // Reinitialize on cart update
});
// Trigger reinitialization when the mini cart is opened
$('.minicart').on('click', function() {
initializePaymentButtons(); // Reinitialize when mini cart is clicked
});
});