WooCommerce_Birthday_Reminder

The WooCommerce Birthday Reminder WooCommerce Birthday Reminder class.

Defined (1)

The class is defined in the following location(s).

/woocommerce-birthday-reminder.php  
  1. final class WooCommerce_Birthday_Reminder { 
  2.  
  3. private static $instance = null; 
  4.  
  5. public static function get_instance() { 
  6. if ( is_null( self::$instance ) ) { 
  7. self::$instance = new self(); 
  8.  
  9. return self::$instance; 
  10.  
  11. public static function plugin_path() { 
  12. return plugin_dir_path( __FILE__ ); 
  13.  
  14. public static function activate() { 
  15. wp_schedule_event( strtotime( date( 'Y-m-d' ) . ' 00:00:01' ), 'daily' , 'check-user-birthday' ); 
  16.  
  17. public static function deactivate() { 
  18. wp_clear_scheduled_hook( 'check-user-birthday' ); 
  19.  
  20. public function __construct() { 
  21. add_action( 'check-user-birthday', array( $this , 'check_birthday' ) ); 
  22. add_filter( 'woocommerce_email_classes' , array( $this , 'add_user_birthday_email' ) ); 
  23.  
  24. public function check_birthday() { 
  25. // Check if today is the first day of the month 
  26. if ( date( 'j' ) == '1' ) { 
  27. // If it's the first day of the month, get all the month birthday users and trigger the action 
  28. $args = array( 
  29. 'meta_key' => 'billing_birthdate',  
  30. 'meta_value' => sprintf( '/%s/' , date( 'm' ) ),  
  31. 'meta_compare' => 'LIKE' 
  32. ); 
  33.  
  34. $users = new WP_User_Query( $args );  
  35.  
  36. if ( ! empty( $users->results ) ) { 
  37. // Trigger the action passing the users as argument 
  38. WC()->mailer()->get_emails(); 
  39. do_action( 'birthdays_users_of_the_month' , $users->results ); 
  40.  
  41. // Get the users with birthday today 
  42. $args = array( 
  43. 'meta_key' => 'billing_birthdate',  
  44. 'meta_value' => sprintf( '^%s' , date( 'd/m' ) ),  
  45. 'meta_compare' => 'REGEXP' 
  46. ); 
  47.  
  48. $users = new WP_User_Query( $args ); 
  49.  
  50. if ( ! empty( $users->results ) ) { 
  51. // Trigger the action for birthday users passing users as argument 
  52. WC()->mailer()->get_emails(); 
  53. do_action( 'birthdays_users_of_the_day', $users->results ); 
  54.  
  55. public function add_user_birthday_email( $email_classes ) { 
  56. require_once( 'class-wc-user-birthday-email.php' ); 
  57. $email_classes['WC_User_Birthday_Email'] = new WC_User_Birthday_Email();; 
  58. return $email_classes;