• Can someone suggest some possible solution of how do I achieve the following in WordPress.

    I have a custom post type named ‘Deals’. On each deal page, I want to have a button which upon clicking will show some coupon code on popup and then that button will be disabled for that particular user forever.

    I know how to create button and show popup, but what will be the way to disable it for that particular user after that?

Viewing 9 replies - 1 through 9 (of 9 total)
  • You are talking about tracking, which is a privacy issue.
    In a lot of countries, you need permission for this, or at least a notice saying you are doing it.
    The method is a cookie or localStorage, but both can be erased. So you can use IP address, but this can also change. If the user is actually logged in to your site, you can store a count in the user meta table.

    Thread Starter vipworks

    (@vipworks)

    Yes, I need the button to function only for logged in users.

    Could you please explain more on how do I store it on user meta table?

    Thread Starter vipworks

    (@vipworks)

    I know how to save meta values.
    My question is how to save it on a per post basis.
    Like on Post A, he clicked the button and it will be disabled.
    but on Post B, he should still be able to click it.

    So it sounds like you want to save user IDs into the post meta instead. (or post IDs in the user meta)

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Or you could set a cookie when the button is first pressed and hide the button if the cookie is set on subsequent page displays.

    Thread Starter vipworks

    (@vipworks)

    Which one would be the best practice.. Cookies or saving user IDs to post meta or saving Post IDs to user meta?

    It just depends on how you want it to work. The user controls their own cookies, so it’s less reliable.
    If you are doing the check when you retrieve the post, you get the post meta and see if the user is there. Or you get the user meta and see if the post is there.
    Either way, it could be a lot of entries.

    1) You can manage this process after manage use login based store meta value
    2) use localStorage Property instead of browser cookie and session.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Disable button after one click per user’ is closed to new replies.