<https://processwire.com/talk/topic/4389-help-in-adding-a-promo-code-to-shopping-cart/#comment-43045>
<http://schema.org/text>
"I've never done this, but the first idea that comes to my mind is to create all the promotions as pages with a field for the code and another for the discount: \n\n-promotions \n--promo1(title, code, discount) \n--promo2(title, code, discount) \n--promo3(title, code, discount) \n\nWhen someone submits a code, you can look for the discount with: \n\n$discount = $pages-&gt;get(\"parent=/promotions/, code=$code\")-&gt;discount;\n\nYou can generate your dscount code with something like this http://stackoverflow.com/questions/3521621/php-code-for-generating-decent-looking-coupon-codes-mix-of-alphabets-and-number (first result on my google search), and make sure that the code is unique by turning that code into a function, and matching the result  against your other discount codes: \n\n// written on the browser and not tested. might be completely wrong \n\nfunction generateCode(){\n    $chars = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n    $res = \"\";\n    for ($i = 0; $i &lt; 10; $i++) {\n        $res .= $chars[mt_rand(0, strlen($chars)-1)];\n    }\n    foreach (wire('pages')-&gt;get(\"parent=/promotions\")-&gt;children as $c) {\n        if ($c-&gt;code == $res) {\n            $res = 0;\n            break;\n        }\n    }\n    if ($res == 0) generateCode();\n    return $res;\n}\n \n"
<https://processwire.com/talk/topic/4389-help-in-adding-a-promo-code-to-shopping-cart/>