Skip Navigation

[Resolved] Create Default Value in CRED

This support ticket is created 8 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by viktorI 8 years, 5 months ago.

Assigned support staff: Minesh.

Author
Posts
#295132

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 ?

#295135

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(
		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

Any Improvement ?

#295378

Minesh
Supporter

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.

#297487

Thanks for clarification