Marcio Vieyra
Marcio Vieyra

Reputation: 129

Send email to WordPress user when Order Status changes?

I'm using a plugin called RestroPress - it's for restaurant delivery.

I want to create a script so that when the $order_statuses is set to 'ready' an e-mail is sent to a specific WordPress user role.

Here's a sample code that includes where I got this info:

function rpress_get_order_statuses() {
    $order_statuses = array(
      'pending'     => __( 'Pending', 'restropress' ),
      'accepted'    => __( 'Accepted', 'restropress' ),
      'processing'  => __( 'Processing', 'restropress' ),
      'ready'       => __( 'Ready', 'restropress' ),
      'transit'     => __( 'In Transit', 'restropress' ),
      'cancelled'   => __( 'Cancelled', 'restropress' ),
      'completed'   => __( 'Completed', 'restropress' ),
    );
    return apply_filters( 'rpress_order_statuses', $order_statuses );
}

Any clues as to how I can do this?

Upvotes: 0

Views: 276

Answers (1)

Harshit Vaishnav
Harshit Vaishnav

Reputation: 69

function send_customer_purchase_notification_ready( $payment_id, $new_status ) {

    $order_status = rpress_get_option( $new_status );

    if ( !empty( $payment_id ) && $new_status !== 'pending' && $new_status == 'ready' ) {                  
        $message = 'Order is ready';
        $to = '[email protected]';
        $subject = "Order is ready";
        $headers = ''; 
        //Here put your Validation and send mail
        $sent = wp_mail($to, $subject, strip_tags($message), $headers);
    }
}
add_action( 'rpress_update_order_status', 'send_customer_purchase_notification_ready' , 10, 2 );

Upvotes: 2

Related Questions