I found myself in a spot of bother: I have a page with an eBook you can read from the browser, access to which I sell through the WooCommerce. The idea is incredibly simple: on the front page is a link, that goes directly to that page. That page checks whether the user is logged in and has bought the product or not, and if not, it redirects him or her to the 'my-account' page with login form.

Question: Can I pass some GET parameter to the 'my-account', say like this:


then process it, of course, to make everything supereasy for the user? He or she logs in and then is redirected back to the page with my eBook, or to the order if the eBook wasn't bought. I'd imagine such functionality is already present in WooCommerce, but I can not find it on the internet.

Maybe I am approaching it from the wrong perspective. I know there are hooks for redirect after login, but GET parameters would not be accessible anyway, am I correct?

I also sell a print version of the book, so universal, permanent redirect is not an option.

Thank you for your time and I appreciate any comments, or answers!

1 Answer 1


The solution seems to be adding the input[type='hidden'] form element called redirect to the login-form.php in wp-content/themes/my-theme/woocommerce/myaccount directory with the value corresponding to your desired address taken from GET parameters. In my case:

<input type="hidden" name="redirect" value="<?= $_GET['redir']; ?>">

Source: WordPress Support Forums

  • The above code introduces an XSS vulnerability as well as an open redirect vulnerability to your login form. Better sanitize via $redirect = wp_validate_redirect(stripslashes($_GET['redirect'])); and <input type="hidden" name="redirect" value="<?php echo esc_attr($redirect); ?>">.
    – le_m
    Feb 17, 2017 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.