Last active
April 5, 2021 20:18
-
-
Save ScottDeLuzio/143fcb124d92b2aa647b72aaba431e27 to your computer and use it in GitHub Desktop.
Filters the discount code generated in Subscriber Discounts for WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'sdwoo_discount_code', 'custom_subscriber_discount_code', 10, 2 ); | |
function custom_subscriber_discount_code( $final_code, $email_address ) { | |
// Start a new discount code. | |
$new_code = '10OFF-'; | |
// Maximum length of the random string of characters after the new code. | |
$max_length = 4; | |
// Choose a random starting point to shorten the string to help avoid repeated strings. | |
$rand_start = rand( 0, 6 ); | |
// Retrieve x = $max_length characters from $final code using a random starting point (0-6). | |
$shortened_sting = substr( $final_code, $rand_start, $max_length ); | |
// Combine the new code with the shortened string. | |
$new_code .= $shortened_string; | |
return $new_code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment