Remove Apple Pay Button on Product, cart & checkout Pages in Stripe Integration for WooCommerce

We introduced it a couple of days ago: Apple Pay is now available for WooCommerce sites using Stripe. That’s great news! But, I noticed that a common request is :

“How can I remove the Apple Pay button on the product page?”

Update: with Stripe 4+, the Apple Pay button has been removed from the checkout page, so the code isn’t accurate anymore

Because yes, the Apple Pay button is displayed on the product page, the cart and the checkout pages. So, here is a small function that will remove the Apple button on the single product page, you just need to copy and paste it in the functions.php file in your theme folder:

<?php
/**
 * Remove Apple Pay button
 *
 * @return bool
 */
function remove_stripe_apple_pay_button() {
	$apple_pay_instance = WC_Stripe_Apple_Pay::instance();

	// Check WooCommerce retro-compatibility.
	if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
		return remove_action( 'woocommerce_after_add_to_cart_button', array( $apple_pay_instance, 'display_apple_pay_button' ), 1 );
	} else {
		return remove_action( 'woocommerce_after_add_to_cart_quantity', array( $apple_pay_instance, 'display_apple_pay_button' ), 1 );
	}
}

add_action( 'init', 'remove_stripe_apple_pay_button', 1 );

What about the cart page?

Also, if you want to remove the Apple Pay button on the cart page you can use this snippet:

<?php
/**
 * Remove Apple Pay button on the cart page
 *
 * @return bool
 */
function remove_stripe_apple_pay_button_on_cart() {
	$apple_pay_instance = WC_Stripe_Apple_Pay::instance();
	remove_action( 'woocommerce_proceed_to_checkout', array( $apple_pay_instance, 'display_apple_pay_button' ), 1 );
	remove_action( 'woocommerce_proceed_to_checkout', array( $apple_pay_instance, 'display_apple_pay_separator_html' ), 2 );
}
add_action( 'init', 'remove_stripe_apple_pay_button_on_cart', 1 );

And what about the checkout page?

and finally, if you want to remove it from the checkout page (…. humm… wait what would you do that?), use this one:

<?php
/**
 * Remove Apple Pay button on the checkout page
 *
 * @return bool
 */
function remove_stripe_apple_pay_button_on_checkout() {
	$apple_pay_instance = WC_Stripe_Apple_Pay::instance();
	remove_action( 'woocommerce_checkout_before_customer_details', array( $apple_pay_instance, 'display_apple_pay_button' ), 1 );
	remove_action( 'woocommerce_checkout_before_customer_details', array( $apple_pay_instance, 'display_apple_pay_separator_html' ), 2 );
}
add_action( 'init', 'remove_stripe_apple_pay_button_on_checkout', 1 );

And that’s it!