get_emails() as $email ) { if ( ! $email->is_customer_email() ) { continue; } add_filter( 'woocommerce_email_enabled_' . $email->id, function ( $enabled, $order ) { return sofrah_board_is_board_order( $order ) ? false : $enabled; }, 20, 2 ); } } ); add_action( 'woocommerce_order_status_on-hold', function ( $order_id, $order = null ) { $order = $order instanceof WC_Order ? $order : wc_get_order( $order_id ); if ( sofrah_board_is_board_order( $order ) && 'awaiting' === sofrah_board_get_status( $order ) && ! $order->get_meta( '_sofrah_board_received_sent' ) ) { $order->update_meta_data( '_sofrah_board_received_sent', time() ); $order->save_meta_data(); sofrah_board_send_diner_email( $order, 'awaiting' ); } }, 20, 2 ); add_action( 'sofrah_board_transitioned', function ( $order_id, $to ) { sofrah_board_send_diner_email( wc_get_order( $order_id ), $to ); }, 10, 2 ); /** * Sends the diner the email for a status, if there is one. * * @param WC_Order $order Order. * @param string $status Board status. */ function sofrah_board_send_diner_email( $order, $status ) { if ( ! sofrah_board_is_board_order( $order ) || ! $order->get_billing_email() || ! function_exists( 'WC' ) ) { return; } $site = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $number = $order->get_order_number(); $pickup = (int) $order->get_meta( '_sofrah_board_pickup_at' ); $reason = (string) $order->get_meta( '_sofrah_board_reason' ); $texts = array( /* translators: %s: order number */ 'awaiting' => array( __( 'Order %s received: not accepted yet', 'sofrah-order-board' ), __( 'We have received your order. The restaurant has not accepted it yet. We will email you as soon as it does, or if it cannot.', 'sofrah-order-board' ) ), /* translators: %s: order number */ 'accepted' => array( __( 'Order %s accepted', 'sofrah-order-board' ), $pickup ? sprintf( /* translators: %s: pickup time */ __( 'The restaurant has accepted your order. Please collect it at %s.', 'sofrah-order-board' ), wp_date( get_option( 'time_format' ), $pickup ) ) : __( 'The restaurant has accepted your order.', 'sofrah-order-board' ) ), /* translators: %s: order number */ 'ready' => array( __( 'Order %s is ready to collect', 'sofrah-order-board' ), __( 'Your order is ready. Please collect it and pay at the counter.', 'sofrah-order-board' ) ), /* translators: %s: order number */ 'rejected' => array( __( 'Order %s not accepted', 'sofrah-order-board' ), sprintf( /* translators: %s: reason */ __( 'Sorry, the restaurant could not accept your order. Reason: %s. You have not been charged.', 'sofrah-order-board' ), $reason ) ), /* translators: %s: order number */ 'cancelled_restaurant' => array( __( 'Order %s cancelled by the restaurant', 'sofrah-order-board' ), sprintf( /* translators: %s: reason */ __( 'Sorry, the restaurant had to cancel your order. Reason: %s. You have not been charged.', 'sofrah-order-board' ), $reason ) ), /* translators: %s: order number */ 'cancelled_diner' => array( __( 'Order %s cancelled', 'sofrah-order-board' ), __( 'You cancelled your order before the restaurant accepted it. Nothing is due.', 'sofrah-order-board' ) ), ); if ( ! isset( $texts[ $status ] ) ) { return; } list( $subject, $message ) = $texts[ $status ]; $subject = sprintf( $subject, $number ); $rows = ''; foreach ( $order->get_items() as $item ) { $meta = array(); foreach ( $item->get_formatted_meta_data() as $m ) { $meta[] = wp_strip_all_tags( $m->display_key . ': ' . $m->display_value ); } $rows .= '
' . esc_html( $message ) . '
'; $body .= '| ' . esc_html( in_array( $status, array( 'rejected', 'cancelled_restaurant', 'cancelled_diner' ), true ) ? __( 'Total (not charged)', 'sofrah-order-board' ) : __( 'To pay at pickup', 'sofrah-order-board' ) ) . ' | ' . wp_kses_post( $order->get_formatted_order_total() ) . ' |
|---|
' . esc_html__( 'See your order status', 'sofrah-order-board' ) . '
'; $mailer = WC()->mailer(); $heading = sprintf( '%s: %s', $site, sofrah_board_status_label( $status ) ); $mailer->send( $order->get_billing_email(), $subject, $mailer->wrap_message( $heading, $body ), array( 'Content-Type: text/html; charset=UTF-8' ) ); }