'How to detect if WooCommerce subscriptions checkout page is for a change payment gateway request?
I have a site using WooCommerce Subscriptions. I do some processing in a woocommerce_available_payment_gateways($available_gateways) filter handler function and I need to detect if the checkout process was triggered by the user wanting to change their payment method for a subscription (woo user docs: https://woocommerce.com/document/subscriptions/customers-view/#section-11).
After a lot of Googling all I could come up with was this:
WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment;
This is a public static property on WC_Subscriptions_Change_Payment_Gateway, but it using it feels a bit nasty!
Does any one know of a cleaner way to do this?
-C
Solution 1:[1]
The URL for change payment gateway request will be looking like www.example.com/checkout/order-pay/1631818391/?pay_for_order=true&key=wc_order_3Qcv1jNShbWNt&change_payment_method=1631818391&_wpnonce=35a514c6ed. So isset() of $_GET['change_payment_method'] can be used in this context.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mujuonly |
