Home Forums ACF PRO Random code field for coupons system Reply To: Random code field for coupons system

  • I have website, and posts, in every post I have text field which called “codename” and repeater field which called “coupons” – it have 3 sub-fields – name, description, code

    For example – I create post, and fill in “EXAMPLE” in the “codename”
    Then I want to create coupons. what I want the system to do is –
    Everytime I’ll click on “add row” I’ll get a new row in the repeater (default behavior), BUT I want the sub-field “code” to get value automatically “EXAMPLE-764” or “EXAMPLE-421” etc…

    I should take automatically the field codename and add to it a 3 digits random number

    To make random number – I know.
    I just need to know:
    1. how to run function when admin click “add row”
    2. how to get the value in other field (before it published…)
    3. how to update the subfield value in the add post page (and not in database, after the post was published, like “update_field” function does)

    Hope it is more understandable now
    Thanks for helping 🙂