Home › Forums › ACF PRO › Random code field for coupons system › Reply To: Random code field for coupons system
Hmmm… this could be tricky.
First… have a peek through this thread here.
You will see that.. in order to pre-populate a repeater, the rows will have to exist ahead of time.
What if…
1) You had a ‘codename’ text field.
2) You had a ‘howmany’ number field (to decide how many codes to generate).
3) You had a textarea field to store your coupons…
… you could store them one per line (and just ‘append’ them when you add more), and then separate the data with a “pipe” | symbol to deal with later. You can use the PHP explode() function to split the data by the “pipe” symbol.
Example:
Codename: EXAMPLE
Howmany: 3
Generated Coupons:
Name1|Description1|Example122
Name2|Description2|Example123
Name3|Description4|Example999
Here’s a page that describes how to extract each line from a textarea field. Then, of course, use ‘explode’ to separate the data from each line.
Hope that helps. There may be a better way, it’s just not coming to me if so 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.