• Hi everyone, I’m setting some coupons for my store. There are 2 types of coupon:
    1. Coupon for everyone
    2. Coupon for a special role (vip customer)

    I use Smart Coupon plugin and successfully apply that logic: all other roles can’t see the coupon of vip in their cart.

    However when I test with not login, I can see all the coupon including the vip one. So I’m finding a way to solve this, maybe force apply the not login users to have Guest or Customer role?

    I appreciate any helps,

    Thanks very much!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot assign roles to users who are not logged in. Whether someone who is logged in can do something or not should be done by verifying a capability with something like:

    // example custom capability and function, they do not exist by default
    if ( current_user_can('view_coupon') show_coupons();

    current_user_can() will return false for non-logged in users, so the above code will prevent them from seeing anything. Adding custom capabilities to roles is not too difficult. There are also plugins that will help with this if you don’t want to do the code yourself.

    You can also conditionally do something or not based on is_user_logged_in() which doesn’t consider role or capability at all.

    As for enforcing capability, that’s the responsibility of the coupon extension. If it’s allowing non-logged in users to see VIP coupons, it’s not properly enforcing capability. I recommend seeking assistance through that module’s dedicated support channel.

Viewing 1 replies (of 1 total)
  • The topic ‘Assign Guest role for not logged in Users’ is closed to new replies.