Customizing personalized customer coupons

There are some filters intended for advanced users which you can use for example to change the default coupon prefix or the coupon code length. You'll find some basic usage examples below.

Change the default coupon prefix

All unique coupons generated by ShopMagic have an sm- prefix by default. If you want to change the default prefix, use the code below:

add_filter( 'shopmagic/coupon/default_prefix', 'sm_custom_default_coupon_prefix' );
/**
 * Change the default coupon prefix
 *
 * @return string
 */
function sm_custom_default_coupon_prefix() {
    return 'abc-';
}

Change the coupon code length

By default, the generated coupons are 10 characters long (plus the prefix). In order to change the length, use the code below:

add_filter( 'shopmagic/coupon/code_length', 'sm_custom_coupon_length' );
/**
 * Change the coupon code length
 *
 * @return int
 */
function sm_custom_coupon_length() {
    return 20;
}

Override the coupon code

If you want to entirely override the generated code (for example by creating your own generator function), you can use the code below:

add_filter( 'shopmagic/coupon/code', 'sm_custom_coupon_code' );
/**
 * @param string $code
 *
 * @return string
 */
function sm_custom_coupon_code( $code ) {
    return md5( $code );
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us