So I’m trying to follow this tutorial but what I want to do is a bit different.
I want to have a unique link per coupon generator and the coupon is per customer and can only be used once (e.g. example.com/coupon/7AD8679adO
).
Now I want to have a form for this page and just have a input boxes for users like first_name
, last_name
, and email
. And the email
field is the identifier that the current url coupon will be registered to that email.
I also tried to research and I found out that there’s URL Coupons feature from Woocommerce
(Not sure though if this is exactly what Im looking for), but suddenly, it is not free. So, any idea with this?
2
Answers
I’m pretty sure you’ve seen this answer elsewhere, but I hope this is written clearly enough for you to understand it better.
It seems as though you may need to implement the "add_rewrite_rule()" in order for WordPress to recognise the element (the unique "/coupon/URL") and pass on the resulting code to the right page.
Additionally, it can sometimes be a bit more difficult to verify a coupon code without the user being logged into an account that can be relied on.
Therefore, I would recommend trying to store the uniquely generated "/coupon/URL" in the user’s meta data, and then querying for the unique in the user’s meta data, and validating the request if the current user and the related user’s ID match. This is because the code doesn’t just get tied to the email address, but also to a registered user.
I have implemented rewrite rule in "twentytwentyone" theme, but you may implement it elsewhere in wordpress.
For more info, please refer to this.
https://developer.wordpress.org/reference/functions/add_rewrite_rule/
Implement in wordpress Theme
~/wp-content/themes/twentytwentyone/functions.php
Implement in wordpress Plugin (Hello Dolly)
~/wp-content/plugins/hello.php
change
to
Refresh permalinks cache
When you add/modify URL part in step1, you need to refresh permalniks cache, otherwise wordress does not apply rewrite rule.
Result
check http://your-domain/coupon/7AD8679adO/