Appointments+ Daily summary email

Hi Hakan,

I don't know if this falls under a feature request or if it's just a matter of a simple tweak.

Is it possible for the App+ mailer to mail a summary of the day's appointments to the SP, say at a set time, so that the SP knows what the day looks like? Or even better: have it mailed at a time chosen by the SP?

That would turn this plugin into a personal secretary of note.

  • Hakan

    Hi,

    This is a customization. You can start from this sample and modify it as required:

    function send_daily_report(){
    	global $wpdb, $appointments;
    	$a = $appointments;
    	// Check if A+ is active
    	if ( !is_object( $a ) )
    		return;
    
    	// Find paid and confirmed appointments today
    	$results = $wpdb->get_results( "SELECT * FROM " . $a->app_table . " WHERE (status='paid' OR status='confirmed') AND DATE_FORMAT(created, '%Y-%m-%d')=CURDATE() " );
    	if ( $results ) {
    		$subject = 'Daily report';
    		$message = "Appointments for today:\n\n";
    		$message .= "Client     Service    Price";
    		foreach ( $results as $r ) {
    			$message .= $a->get_client_name( $r->ID );
    			$message .= '     ';
    			$message .= $a->get_service_name( $r->service );
    			$message .= '     ';
    			$message .= $r->price;
    			$message .= '\n';
    		}
    		wp_mail( 'mail@example.com', $subject, $message, $a->message_headers() );
    	}
    }
    add_action( 'send_daily_report_hook', 'send_daily_report' );
    
    function activate_report(){
    // Start at 23:59 today and repeat daily.
    if ( !wp_next_scheduled( 'send_daily_report_hook' ) )
    wp_schedule_event( strtotime( date("Y-m-d" ) . ' 23:59:00', current_time('timestamp') ), 'daily', 'send_daily_report_hook' );
    }
    add_action('wp', 'activate_report');

    Note: As wp_cron relies on someone visiting your website, you will need to trigger it after 23:59. Of course you can use another time of the day and check past 24 hour appointments.

    See this post:
    https://premium.wpmudev.org/forums/topic/reminder-emails#post-299967

    Cheers,
    Hakan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.