Skip Navigation

[Résolu] 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.

Marqué : 

This topic contains 3 réponses, has 2 voix.

Last updated by viktorI Il y a 6 années et 6 mois.

Assigned support staff: Minesh.

Auteur
Publications
#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: Anglais (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