I have a WooCommerce checkout page that makes an AJAX call to place an order when the form is submitted. I need to catch the value of the redirect URL in the success response and extract parameters and substrings from it into variables so I can build a different redirect URL to send to the payment gateway.
How can I use frontend jQuery on that page to access the value in the AJAX success response and do what I need?
I am really a beginner with Javascript, Ajax and jQuery so I need detailed guidance, please.
The AJAX response is (as can be found in the console):
{result: "success", redirect: "https://example.com/checkout/order-pay/1234/?key=wc_order_xyz"}
This is the frontend script I have right now:
<script>
jQuery(document).ajaxSuccess(function(event) {
event.preventDefault();
//get Success response and extract substrings into variables...
window.location.href = "new redirect URL"; //Build a new URL
});
</script>
I need to build a new Redirect URL like this to use in the above function:
https://example.com/thank-you-page/wcf-key=wc_order_xyz&wcf-order=1234