I am trying to generate coupon code, i already create the shortcode for the coupon, now what i need in CRED is :
1. Make a field become hidden. Can i use type="hidden" or must use class ?
2. Set the hidden field with the generated coupon code.
function getvoucher($atts){
global $vouchercode;
$atts = shortcode_atts(
array(
'type' => 'default bar',
), $atts );
/*Generate Voucher Code*/
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$res = "";
for ($i = 0; $i < 10; $i++) {
$res .= $chars[mt_rand(0, strlen($chars)-1)];
}
$vouchercode=$res;
/*END Generate Voucher Code*/
$durasi=345600; //4 hari
switch($atts['type']){
case '1':
$vouchercode="AD-".$vouchercode;
break;
default:
$vouchercode="SE-".$vouchercode;
break;
}
return $vouchercode;
}
function showvoucher(){
global $vouchercode;
return $vouchercode;
}
There are two thing that i don't think its a best practice:
- The usage of global variables
- using external wordpress capabilities instead of built-in feature of toolset