Hey @trungtuans,
Thank you for reaching out! I’m afraid that currently we do not have this particular feature, neither in the free plugin or the pro plugin.
Even so, I do want to know more about your business and add your feedback to our development log for future research and development. Can you please let me know why you’d like to have coupons automatically created? Furthermore, can you please let me know what kind of discounts are you looking to offer via these coupons? Also, if you can let me know which eCommerce plugin you’re using that would be helpful.
Thank you and best wishes,
Mihai
Thank you for your response.
Your plugin does support coupon affiliates, but the issue is that I have to manually create and assign a coupon each time a new affiliate registers. This process becomes inefficient when dealing with hundreds of new affiliates daily.
I’ve spent the past month testing demos and researching other plugins like Solid Affiliate, WP Affiliate, and Coupon Affiliate. Most of them offer automatic coupon generation upon registration, but they are either too expensive or bloated. SliceWP is the closest fit for my needs—simple, well-priced, and feature-rich—but lacking this one crucial feature has been a big drawback for me.
Is there any available PHP hook, action, or filter that I could use to automate coupon creation and assignment to new affiliates?
Hey @trungtuans,
Thank you for sharing all of these details! Considering the other plugins you’ve researched, I’m guessing you’re using WooCommerce to power your business.
If so, I have found a code snippet in our snippet library that will help in this case:
function slicewp_custom_affiliate_insert_generate_affiliate_coupon( $affiliate_id ) {
$coupon = new WC_Coupon();
$coupon->set_code( slicewp_custom_generate_random_unique_code( 10 ) );
$coupon->set_discount_type( 'percent' );
$coupon->set_amount( 50 );
$coupon->add_meta_data( 'slicewp_affiliate_id', $affiliate_id );
$coupon->save();
}
add_action( 'slicewp_insert_affiliate', 'slicewp_custom_affiliate_insert_generate_affiliate_coupon' );
function slicewp_custom_generate_random_unique_code( $length ) {
$code = strtoupper( _slicewp_generate_random_string( $length ) );
$id = wc_get_coupon_id_by_code( $code );
if ( ! empty( $id ) ) {
return slicewp_custom_generate_random_unique_code( $length );
}
return $code;
}
When a new affiliate is added to the database, a new 10 characters long random coupon code is created and linked to the new affiliate.
Please make sure to adapt this code to your needs.
Thank you and best wishes,
Mihai
Thank your for the code! I’ll try it.