Generating coupon codes programatically
-
Hi,
I have succesfully write a small snippet to generate coupon codes from an array. Everything works except, the title of the coupon codes.
My snippet, which is from WooCommerce pages.
So this will generate two coupons, but the title has no leading zeros as my array elements. See this.
I have also tried woocommerce_coupon_code hook.
/*-----------------------------------------------------------------------------------*/ /* Add Leading Zeros before coupon codes generating */ /*-----------------------------------------------------------------------------------*/ function zerofill ($num, $zerofill = 8) { return str_pad($num, $zerofill, '0', STR_PAD_LEFT); } // add the filter add_filter( 'woocommerce_coupon_code', 'filter_woocommerce_coupon_code', 10, 1 ); // define the woocommerce_coupon_code callback function filter_woocommerce_coupon_code( $post_post_title ) { //error_log("COUPON: ".$post_post_title); return zerofill($post_post_title); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Generating coupon codes programatically’ is closed to new replies.