I need some help. I am trying to prevent direct access to a page that my customers get redirected to after checkout. I want the page to be accessible only after checkout.
I have found this topic: https://wordpress.stackexchange.com/questions/290234/prevent-block-direct-access-to-a-thank-you-page
I placed the following code snippet to my functions.php:
add_action('template_redirect', function() {
// ID of the redirect page
if (!is_page(2072)) {
return;
}
// URL of checkout page
if (wp_get_referer() === 'https://www.exampledomain.com/checkout/') {
return;
}
// we are on thank you page
// visitor is not coming from form
// so redirect to home
wp_redirect(get_home_url());
exit;
} );
This works fine if the customer pays through Stripe. However, it does not work if the customer chooses to pay through PayPal because PayPal redirects the customer to their website to make the payment.
Can something be done here to fix this issue?