array( title, to, subject, heading, text, blocks[, more] ). Defaults; the shop's own versions * are in dayslot_settings['emails'][ id ]. */ function dayslot_emails() { return apply_filters( 'dayslot_emails', array( 'date_change' => array( 'title' => __( 'New delivery date (when you change it)', 'dayslot' ), 'to' => 'customer', /* translators: {shop}, {order}: placeholders, keep them */ 'subject' => __( '[{shop}] New delivery date for order #{order}', 'dayslot' ), 'heading' => __( 'Your delivery date has changed', 'dayslot' ), 'text' => __( 'Hi {name}, the delivery date for your order #{order} has been changed: {details} If this doesn\'t suit you, just reply to this email.', 'dayslot' ), 'blocks' => array( 'details', 'calendar', 'contact' ), ), ) ); } /** * Blocks an e-mail can show: id => label. */ function dayslot_email_blocks() { return array( 'details' => __( 'Delivery details (date, time, address)', 'dayslot' ), 'products' => __( 'Products with photos', 'dayslot' ), 'prices' => __( 'Prices and total', 'dayslot' ), 'calendar' => __( '"Add to calendar" links', 'dayslot' ), 'contact' => __( 'Shop contact in the footer', 'dayslot' ), ); } /** * One e-mail with the shop's changes: array( subject, heading, text, blocks ). */ function dayslot_email_template( $id ) { $all = dayslot_emails(); if ( ! isset( $all[ $id ] ) ) { return null; } // The shop's own texts and blocks (set on the Pro E-mails tab). $own = (array) dayslot_get_settings()['emails']; $own = isset( $own[ $id ] ) && is_array( $own[ $id ] ) ? $own[ $id ] : array(); $out = array(); foreach ( array( 'subject', 'heading', 'text' ) as $key ) { $out[ $key ] = isset( $own[ $key ] ) && '' !== trim( (string) $own[ $key ] ) ? (string) $own[ $key ] : $all[ $id ][ $key ]; } $out['blocks'] = isset( $own['blocks'] ) && is_array( $own['blocks'] ) ? $own['blocks'] : ( isset( $all[ $id ]['blocks'] ) ? $all[ $id ]['blocks'] : array() ); return $out; } /** * Colours for the plain (WooCommerce) look. */ function dayslot_email_palette() { return array( 'id' => 'woo', 'text' => '#1f2430', 'muted' => '#5b6270', 'accent' => get_option( 'woocommerce_email_base_color', '#242e42' ), 'on' => '#ffffff', 'box' => '#f6f7f9', 'line' => '#e6e8eb', 'btnr' => 8, ); } /** * The look of the e-mails: the WooCommerce one; Pro adds its own designs (filter "dayslot_email_look"). */ function dayslot_email_look( $style = null, $color = null ) { return (array) apply_filters( 'dayslot_email_look', array( 'id' => 'woo' ), $style, $color ); } /** * The delivery rows of an order as a table. */ function dayslot_email_details( $order, $t = null ) { $t = $t ? $t : dayslot_email_look(); $muted = isset( $t['muted'] ) ? $t['muted'] : '#636363'; $box = isset( $t['box'] ) ? $t['box'] : '#f6f7f9'; $line = isset( $t['line'] ) ? $t['line'] : '#e5e5e5'; $rows = dayslot_order_summary_rows( $order ); unset( $rows['dayslot_price'] ); if ( ! $rows ) { return ''; } $html = '
| ' . esc_html( $row['label'] ) . ' | ' . esc_html( $row['value'] ) . ' |
' . esc_html__( 'Your order', 'dayslot' ) . '
| ' . wp_kses_post( wc_price( $order->get_line_total( $item, true ), $args ) ) . ' | ' : ''; $html .= '|
| ' . $pic . ' | ' . esc_html( $item->get_name() ) . ' × ' . esc_html( $item->get_quantity() ) . ' | ' . $price . '
| ' . esc_html( $order->get_shipping_method() ? $order->get_shipping_method() : __( 'Delivery', 'dayslot' ) ) . ' | ' . wp_kses_post( wc_price( (float) $order->get_shipping_total() + (float) $order->get_shipping_tax(), $args ) ) . ' |
| ' . esc_html__( 'Total', 'dayslot' ) . ' | ' . wp_kses_post( wc_price( $order->get_total(), $args ) ) . ' |
', '
', $out ); } $out .= $details; if ( $order && isset( $blocks['products'] ) ) { $out .= dayslot_email_products( $order, $woo ? dayslot_email_palette() : $t, isset( $blocks['prices'] ) ); } elseif ( $order && isset( $blocks['prices'] ) ) { $out .= dayslot_email_prices( $order, $woo ? dayslot_email_palette() : $t ); } if ( $order && isset( $blocks['calendar'] ) && function_exists( 'dayslot_customer_event' ) && 'yes' === dayslot_get_settings()['add_to_calendar'] ) { $event = dayslot_customer_event( $order ); if ( $event ) { $link = 'font-weight:bold;color:' . ( $woo ? '#242e42' : $t['accent'] ); if ( ! $woo && in_array( $t['id'], array( 'soft', 'elegant' ), true ) ) { $link = 'font-weight:bold;color:' . ( isset( $t['brand'] ) ? $t['brand'] : $t['text'] ); } $out .= '
' . esc_html__( 'Add to calendar:', 'dayslot' ) . ' Google · Apple / Outlook
'; } } $subject = wp_strip_all_tags( strtr( $tpl['subject'], $values ) ); $heading = wp_strip_all_tags( strtr( $tpl['heading'], $values ) ); return array( 'subject' => $subject, 'heading' => $heading, 'body' => $out, 'html' => $woo || ! function_exists( 'dayslot_pro_email_wrap' ) ? '' : dayslot_pro_email_wrap( $t, $heading, $out, $order, isset( $blocks['contact'] ) ), ); } /** * Compose and send. Returns true when WooCommerce sent it. */ function dayslot_email_send( $id, $to, $order = null, $plain = array(), $html = array() ) { $mail = dayslot_email_compose( $id, $order, $plain, $html ); if ( ! $mail || ! $to || ! function_exists( 'WC' ) ) { return false; } $mailer = WC()->mailer(); $body = $mail['html'] ? $mail['html'] : $mailer->wrap_message( $mail['heading'], $mail['body'] ); return (bool) $mailer->send( $to, $mail['subject'], $body ); } add_filter( 'dayslot_default_settings', function ( $d ) { $d['emails'] = array(); return $d; } );