send mail in every on minute in wordpress through cron

Solutions on MaxInterview for send mail in every on minute in wordpress through cron by the best coders in the world

showing results for - "send mail in every on minute in wordpress through cron"
Louann
17 Apr 2016
1/**
2 * @snippet       Schedule Email to WooCommerce Admin Every 3 Hours
3 * @how-to        Get CustomizeWoo.com FREE
4 * @sourcecode    https://businessbloomer.com/?p=106360
5 * @author        Rodolfo Melogli
6 * @compatible    WooCommerce 3.5.4
7 * @donate $9     https://businessbloomer.com/bloomer-armada/
8 */
9 
10// ---- ---- ----
11// A. Define a cron job interval if it doesn't exist
12 
13add_filter( 'cron_schedules', 'bbloomer_check_every_3_hours' );
14 
15function bbloomer_check_every_3_hours( $schedules ) {
16    $schedules['every_three_hours'] = array(
17        'interval' => 10800,
18        'display'  => __( 'Every 3 hours' ),
19    );
20    return $schedules;
21}
22 
23// ---- ---- ----
24// B. Schedule an event unless already scheduled
25 
26add_action( 'wp', 'bbloomer_custom_cron_job' );
27 
28function bbloomer_custom_cron_job() {
29   if ( ! wp_next_scheduled( 'bbloomer_woocommerce_send_email_digest' ) ) {
30      wp_schedule_event( time(), 'every_three_hours', 'bbloomer_woocommerce_send_email_digest' );
31   }
32}
33 
34// ---- ---- ----
35// C. Trigger email when hook runs
36 
37add_action( 'bbloomer_woocommerce_send_email_digest', 'bbloomer_generate_email_digest' );
38 
39// ---- ---- ----
40// D. Generate email content and send email if there are completed orders
41 
42function bbloomer_generate_email_digest() {   
43   $range = 180; // 3 hours in minutes
44   $completed_orders = bbloomer_get_completed_orders_before_after( strtotime( '-' . absint( $end ) . ' MINUTES', current_time( 'timestamp' ) ), current_time( 'timestamp' ) );
45   if ( $completed_orders ) {
46      $email_subject = "Completed Orders Email Digest";
47      $email_content = "Completed Order IDs: " . implode( "|", $completed_orders );
48      wp_mail( 'your@email.com', $email_subject, $email_content );
49   }
50}
51 
52// ---- ---- ----
53// E. Query WooCommerce database for completed orders between two timestamps
54 
55function bbloomer_get_completed_orders_before_after( $date_one, $date_two ) {
56   global $wpdb;
57   $completed_orders = $wpdb->get_col(
58      $wpdb->prepare(
59         "SELECT posts.ID
60         FROM {$wpdb->prefix}posts AS posts
61         WHERE posts.post_type = 'shop_order'
62         AND posts.post_status = 'wc-completed'
63         AND posts.post_modified >= '%s'
64         AND posts.post_modified <= '%s'",
65         date( 'Y/m/d H:i:s', absint( $date_one ) ),
66         date( 'Y/m/d H:i:s', absint( $date_two ) )
67      )
68   );
69   return $completed_orders;
70}
71