Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
173 stars 69 forks source link

Conflict with woocommerce_available_payment_gateways #4219

Open BusinessBloomer opened 2 years ago

BusinessBloomer commented 2 years ago

How to reproduce the issue:

1) use woocommerce_available_payment_gateways to disable WooCommerce Payments when a certain shipping method is selected e.g. from https://www.businessbloomer.com/woocommerce-disable-payment-gateway-for-specific-shipping-method/:

add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_gateway_disable_for_shipping_rate' );

function bbloomer_gateway_disable_for_shipping_rate( $available_gateways ) {
   if ( ! is_admin() ) {
      $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
      $chosen_shipping = $chosen_methods[0];
      if ( isset( $available_gateways['woocommerce_payments'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
         unset( $available_gateways['woocommerce_payments'] );
      }
   }
   return $available_gateways;
}

2) all good, but in a scenario the bug occurs: select the shipping method that hides WooCommerce Payments @ Cart, go to Checkout, so that the shipping method is selected and WooCommerce Payments is hidden (so, woocommerce_available_payment_gateways triggers ok).

Now, switch shipping rate, so that WooCommerce Payments appears again (woocommerce_available_payment_gateways triggers ok again). The Credit Card form does not load: https://www.screencast.com/t/SkvyVs0RXdc6

Basically, it seems that “on checkout load”, if the WooCommerce Gateway is unset, whatever Stripe JS does not run. When you switch shipping and WooCommerce Payments appear back, this JS does not load, and therefore there is no payment card form

Are you able to replicate this?

BusinessBloomer commented 2 years ago

p.s. The exact same bug happens with the new WooCommerce PayPal Payments plugin: if on load PayPal is unset, and I switch shipping rate, PayPal appears but displays no buttons

johnaps94 commented 2 years ago

I have found a relative problematic behavior when the payment method is getting hidden. Whichever option i choose after the payment option gets hidden, it takes me to my credit card payment option... Which on 1st position after unsetting 'woocommerce_payments'.

MSuar commented 1 year ago

I'm sure it's too late. but the code is limited to an environment outside of the manager! is_admin() and the ajax response is done within the admin. Therefore the answer does not include the code inside if(!is_admin()) statement