Skip to content

Instantly share code, notes, and snippets.

@dougaitken
Last active August 11, 2022 10:59
Show Gist options
  • Save dougaitken/79922e6a8e0999307dd719f25e98b36a to your computer and use it in GitHub Desktop.
Save dougaitken/79922e6a8e0999307dd719f25e98b36a to your computer and use it in GitHub Desktop.
[broken] Moving the WooCommerce Stripe Payment Request buttons below the add to cart button
I'm removing this for now as it broke some point due to code changes. I may revert in the future. I'm glad it helped some folks in the past.
@timbrandon
Copy link

Sweet! Thank you! Just what I was looking for!

@mailvikastaneja
Copy link

Hello, I have the same issue but for some reason it is not getting fixed when I try to use the above code in my child theme. So when Apple pay button is available in Safari on my iphone the Add to cart button drops below the apple pay button but when the payment button is not available say in chrome then the add to cart button shows up at a correct place. please check my website product page which is still under development - itsmygadget.com Could you please advise. Thanks.

@mailvikastaneja
Copy link

hi Figured it out with your above code. Sharing so other could also use it until a solution is rolled out for this known issue here -
woocommerce/woocommerce-gateway-stripe#832

The fix is to go to file
woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php

and replace code
if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
} else {
add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
}

with
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 2 );
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 1 );

hope this helps.

@gianvitofanelli
Copy link

Hi, I tried this snippet, but every time I run it, I receive a critical error. What could it be the cause?

Thank you

@oempire
Copy link

oempire commented Jul 17, 2020

Hi Doug, how can we wrap this is a function_exists check to see if stripe is active? because if you disable woo-commerce while troubleshooting it throws a Uncaught Error: Class 'WC_Stripe_Payment_Request' not found

@mailvikastaneja
Copy link

Just updated the Stripe plugin to 4.5.2 and had the same issue again. Had to again replace the

add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );

with

add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 2 );
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 1 );

Is it not possible to accomodate the display of payment button after the add to cart button somehow so that with the next update of the plugin we do not have to manually adjust it? Thanks.

@alcoolio
Copy link

awesome, thanks mate!

@espiat
Copy link

espiat commented Dec 20, 2021

Thanks for the code.

I find out not to change the code in the plugin - because its bad practice.

add_action('init', 'der_spanier_change_stripe_express_checkout_woo_position_after_buy_button', 11);
function der_spanier_change_stripe_express_checkout_woo_position_after_buy_button()
{

	remove_action('woocommerce_after_add_to_cart_quantity', array(WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_html'), 1);

	remove_action('woocommerce_after_add_to_cart_quantity', array(WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_separator_html'), 2);

	add_action('woocommerce_after_add_to_cart_button', array(WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_html'), 2);

	add_action('woocommerce_after_add_to_cart_button', array(WC_Stripe_Payment_Request::instance(), 
'display_payment_request_button_separator_html'), 1);

}

Merry christmas

PS: It is a mystery to me why the Stripe plugin dispels this nonsense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment