PayPal button doesn’t show unless Checkout is reloaded
-
We have PayPal and Stripe. We’d like to enable PayPal for US, CA and PR and Stripe for the RoW. We’re using
woocommerce_available_payment_gateways
hook to enable / disable providers based on county. This works as expected and it toggles correct payment provider. But for PayPal the yellow pay button doesn’t show up until the user reloads the checkout page.add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_countries' ); if ( ! function_exists( 'payment_gateway_disable_countries' ) ) { function payment_gateway_disable_countries( $gateways ) { if ( is_admin() ) { return $gateways; } if ( ! is_object( WC()->customer ) OR ! method_exists( WC()->customer, 'get_billing_country' ) ) { return $gateways; } $paypal_countries = array('US', 'CA', 'PR'); if ( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page $order = wc_get_order( wc_get_order_id_by_order_key( $_GET[ 'key' ] ) ); $country = $order->get_billing_country(); } else { // Cart page $country = WC()->customer->get_billing_country(); } // Disable PayPal if ( ! in_array( $country, $paypal_countries ) ) { if ( isset( $gateways['ppcp-gateway'] ) ) { unset( $gateways['ppcp-gateway'] ); } } else { if ( isset( $gateways['stripe'] ) ) { unset( $gateways['stripe'] ); } } return $gateways; } }
To Reproduce
- Go to ‘Checkout’
- If the billing country is not US, CA or Canada click on ‘Country selector’ and select any of these countries
- Now Stripe is disabled and PayPal is enabled. However the PayPal button is not shown.
- Reload
Checkout
and now PayPal button is shown
Screenshots
Correct behaviour: Billing country is not US, CA or PR. Stripe is enabled and PayPal is disabled.Wrong behaviour: Billing country is US. Stripe is disabled and PayPal is enabled. But PayPal button doesn’t show. Even after filling all the checkout fields, the button doesn’t show.
After reloading the page, the PayPal button shows.
Environment
- WordPress Version: 6.2
- WooCommerce Version: 7.4.0
- Plugin Version: 2.0.4
So, PayPal button needs to show without the need for reloading. How can I accomplish this?
- The topic ‘PayPal button doesn’t show unless Checkout is reloaded’ is closed to new replies.