Friday, November 11, 2022

[FIXED] How to detect if WooCommerce subscriptions checkout page is for a change payment gateway request?

Issue

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

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.



Answered By - mujuonly
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.