Last active
November 30, 2018 07:26
-
-
Save wpweb101/4b0678eef2fd1abc58c776557cc9deb7 to your computer and use it in GitHub Desktop.
PDF Voucher code for 4272
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
| <?php | |
| //Change voucher code to order number and 3-digit random number | |
| function woo_vou_unlimited_code_pattern_modification( $voucodes_args = array() ) { | |
| if( !empty( $voucodes_args ) && array_key_exists( 'order_id', $voucodes_args ) ) { | |
| $digits = 3; // Amount of digits | |
| $min = pow(10, $digits - 1 ); | |
| $max = pow(10, $digits ) - 1; | |
| $value = rand($min, $max); | |
| $value = str_shuffle($value); | |
| $order_number = get_post_meta( $voucodes_args['order_id'], '_order_number', true ); | |
| if ( !empty($order_number) ) { | |
| $voucode_args['order_id'] = $order_number.$value; | |
| // $voucode_args['order_id'] = $order_number.str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT); | |
| } else { | |
| $voucode_args['order_id'] = $voucodes_args['order_id'].$value; | |
| //$voucode_args['order_id'] = $voucodes_args['order_id'].str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT); | |
| } | |
| } | |
| return $voucode_args; | |
| } | |
| add_filter( 'woo_vou_unlimited_code_pattern', 'woo_vou_unlimited_code_pattern_modification' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment