Support

Account

Home Forums Add-ons Options Page User role option / custom field

Solving

User role option / custom field

  • Hey,
    I’m a happy user of ACF Pro and particularly of the excellent Options Page feature.
    However today I’m facing a problem with a project for a customer : I need to be able to add a custom field for each user role available. To be clear, my customer wants to apply a discount percentage to a user depending on the user’s role.
    I’m trying to figure out how to do this with ACF but with no luck so far. If anyone has a suggestion for this issue, I’d really appreciate it.

    Another approach I can think of is to add a custom section to an option page, not managed via ACF, and in which I’d add my own full PHP code. Is this even possible?

    Best
    Dale

  • I would probably add a custom field to an options page for each user role that the client wants to set this for. I would name the fields something like

    discount_{$user_role}

    where $user_role represents the name of each role.

    Then when you need to get the value you first get the user role of the current user and then you can get the discount with a single line of code

    $discount = get_field("discount_{$user_role}", 'options');

  • Thank you so much for the suggestion. It’s not an ideal solution because I need the roles to be dynamically available since the client will be free to create new roles anytime.
    In the meantime I’ve found a way to add a “regular” custom options page to an ACF options page group in the menu, that will do the trick perfectly!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.