Suggestion
-
Just a suggestion:
Change:
$final_code .= $letters_array[ $value ];
to:
$final_code .= strtoupper($letters_array[ $value ]);This makes the code uppercase and easy to read.
You can also use the following code generation function instead of your way. This will generate a unique ID:
function genUniqueId( $bytes = 10) {
return bin2hex(random_bytes($bytes));
}$final_code = genUniqueId();
Or you could also add a setting inside you options:
$final_code = genUniqueId( $this->sdwoo_options[ ‘code_length’ ] );Also, I would add the discount amount to your variables to be used inside the email:
$discount_amount =( $this->sdwoo_options[ ‘discount_type’ ] == ‘percent’ ) ? $this->sdwoo_options[ ‘discount_amount’ ].’%’ : ‘$’$this->sdwoo_options[ ‘discount_amount’ ];
$vars = array(
‘{firstname}’ => esc_html( $first_name ),
‘{code}’ => esc_html( $final_code ),
‘{discount}’ => esc_html( $discount_amount ),
);Last but not least, remove the text “simple HTML is allowed” as every HTML code is allowed and you should pre-fill it with a sample proper HTML mailing.
You also could extend your solution to add a “redeem your code” button which automatically add the code similar to this:
And if you are super keen, you can add a {button} to you var array which generates a redeem button based on option settings. E.g:
<div align=”center”><!–[if mso]>
<v:roundrect xmlns:v=”urn:schemas-microsoft-com:vml” xmlns:w=”urn:schemas-microsoft-com:office:word” href=”get_home_url()/?coupon_code={code}” style=”height:50px;v-text-anchor:middle;width:200px;” arcsize=”8%” stroke=”f” fillcolor=”{button_color}”>
<w:anchorlock/>
<center>
<![endif]–>
<a href=”get_home_url()/?coupon_code={code}”
style=”background-color:{button_color};border-radius:4px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:13px;font-weight:bold;line-height:50px;text-align:center;text-decoration:none;width:200px;-webkit-text-size-adjust:none;”>{button_text}
<!–[if mso]>
</center>
</v:roundrect>
<![endif]–></div>
- The topic ‘Suggestion’ is closed to new replies.