Advertisement
wpgenie

add zeroes (0) in front of ticket numbers

Oct 28th, 2020 (edited)
2,189
1
Never
7
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.26 KB | None | 1 0
  1. add_filter( 'ticket_number_display_html' , 'custom_change_prefic_ticket_numbers', 10, 2 );
  2. function custom_change_prefic_ticket_numbers ($data, $product){
  3.     $digits = strlen( $product->get_max_tickets() );
  4.     return str_pad($data, $digits, '0', STR_PAD_LEFT);
  5. }
Advertisement
Comments
  • OzRin
    1 year
    # text 0.30 KB | 0 0
    1. Any Code where Raffle can start at 0 as a digit and proceed to fill in the 0s if chosen a 2,3,4,or 5 digit Winner Number? Example start at 000 and proceed up to 999 if the max number of tickets is 1,000. Another example is with 4 digits if max number of tickets is 10,000 and so on (0000, 0001, 0002, etc.)
    • wpgenie
      1 year
      Comment was deleted
    • wpgenie
      1 year
      # text 0.18 KB | 1 0
      1. This code has to do exactly that just change priority of filter to fit your needs.
      2. For example
      3. add_filter( 'ticket_number_display_html' , 'custom_change_prefic_ticket_numbers', 90, 2 );
      • OzRin
        1 year
        # text 0.16 KB | 0 0
        1. I'm having issues making the raffle start at ticket number 0 or 00 or 000, Being 0 as a Ticket Number and then finish in 99 instead of 100 and 999 instead of 1000 etc.
      • OzRin
        1 year
        # text 1.20 KB | 0 0
        1. The best I found is:
        2.  
        3. add_filter( 'ticket_number_display_html' , 'custom_change_prefic_ticket_numbers', 10, 2 );
        4. function custom_change_prefic_ticket_numbers($data, $product) {
        5. $max_tickets = $product->get_max_tickets();
        6. $ticket_number = str_pad($data, strlen((string)$max_tickets), '0', STR_PAD_LEFT);
        7. return substr($ticket_number, -3); // Truncate to 3 digits
        8. }
        9.  
        10. "Chat-GPT Help"
        11.  
        12. This helps visually making the last number of the raffle "1,000" as 000 eliminating the extra 1 or digit space where 0 would have been filled in other lower numbers.
        13.  
        14. I still cannot make the raffle start at ticket Number 000 when max number is set to 1,000. This would be best as per our raffle needs. This way when visually looking at the numbers they will see 1st ticket as 000 and the last ticket as 999 Considering this raffle is for 1,000 total tickets.
        15.  
        16. Also this is for a particular raffle considering last 3 digits of National Raffle results.
        17.  
        18. But other raffles that I will be hosting will be considering the last 2 Digits and some even up to last 4 digits or 5 digits.
        19.  
        20. So how can this code be implemented in PARTICULAR LOTTERY PRODUCT Instead of all lottery products?
        21. Thanks for your response! 🤜🤛
  • OzRin
    1 year
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement