Skip Navigation

[Resolved] Create Default Value in CRED

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.


This topic contains 3 replies, has 2 voices.

Last updated by viktorI 6 years, 7 months ago.

Assigned support staff: Minesh.


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.

What would you suggest for this approach ?


At the moment i use:

<h3>[getcoupon type="1"]</h3>
			[cred_field field="coupon" post="newlifepromo" value="[showcoupon]" urlparam="" class="hidden"]

And on functions.php i use :

function getvoucher($atts){
	global $vouchercode;
	$atts = shortcode_atts(
			'type' => 'default bar',
		), $atts );
        /*Generate Voucher Code*/
	$res = "";
	for ($i = 0; $i < 10; $i++) {
		    $res .= $chars[mt_rand(0, strlen($chars)-1)];
        /*END Generate Voucher Code*/
         $durasi=345600; //4 hari
			case '1':
	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

Any Improvement ?



Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I have review the code submitted by you and we think you are on the right track. The way you have coded we believe that's the best way to follow.


Thanks for clarification