|
2 | 2 | /**
|
3 | 3 | * Order/Subscription details table shown in emails.
|
4 | 4 | *
|
5 |
| - * @author Prospress |
| 5 | + * Based on the WooCommerce core email-order-details.php template. |
| 6 | + * |
6 | 7 | * @package WooCommerce_Subscriptions/Templates/Emails
|
7 |
| - * @version 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.0 |
| 8 | + * @version 7.3.0 |
8 | 9 | */
|
9 |
| -if ( ! defined( 'ABSPATH' ) ) { |
10 |
| - exit; // Exit if accessed directly |
11 |
| -} |
| 10 | + |
| 11 | +defined( 'ABSPATH' ) || exit; |
12 | 12 |
|
13 | 13 | $text_align = is_rtl() ? 'right' : 'left';
|
14 | 14 |
|
| 15 | +$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' ); |
| 16 | +$heading_class = $email_improvements_enabled ? 'email-order-detail-heading' : ''; |
| 17 | +$order_table_class = $email_improvements_enabled ? 'email-order-details' : ''; |
| 18 | +$order_total_text_align = $email_improvements_enabled ? 'right' : 'left'; |
| 19 | + |
| 20 | +if ( $email_improvements_enabled ) { |
| 21 | + add_filter( 'woocommerce_order_shipping_to_display_shipped_via', '__return_false' ); |
| 22 | +} |
| 23 | + |
15 | 24 | do_action( 'woocommerce_email_before_' . $order_type . '_table', $order, $sent_to_admin, $plain_text, $email );
|
16 | 25 |
|
17 |
| -if ( 'cancelled_subscription' != $email->id ) { |
18 |
| - echo '<h2>'; |
| 26 | +if ( 'cancelled_subscription' !== $email->id ) { |
| 27 | + echo '<h2 class="' . esc_attr( $heading_class ) . '">'; |
19 | 28 |
|
20 |
| - $link_element_url = ( $sent_to_admin ) ? wcs_get_edit_post_link( wcs_get_objects_property( $order, 'id' ) ) : $order->get_view_order_url(); |
| 29 | + $id_heading = sprintf( |
| 30 | + /* translators: %s: Order or subscription ID. */ |
| 31 | + ( 'order' === $order_type ) ? __( 'Order #%s', 'woocommerce-subscriptions' ) : __( 'Subscription #%s', 'woocommerce-subscriptions' ), |
| 32 | + $order->get_order_number() |
| 33 | + ); |
21 | 34 |
|
22 |
| - if ( 'order' == $order_type ) { |
23 |
| - // translators: $1-$2: opening and closing <a> tags $3: order's order number $4: date of order in <time> element |
24 |
| - printf( esc_html_x( '%1$sOrder #%3$s%2$s (%4$s)', 'Used in email notification', 'woocommerce-subscriptions' ), '<a href="' . esc_url( $link_element_url ) . '">', '</a>', esc_html( $order->get_order_number() ), sprintf( '<time datetime="%s">%s</time>', esc_attr( wcs_get_objects_property( $order, 'date_created' )->format( 'c' ) ), esc_html( wcs_format_datetime( wcs_get_objects_property( $order, 'date_created' ) ) ) ) ); |
| 35 | + if ( $email_improvements_enabled ) { |
| 36 | + $heading = ( 'order' === $order_type ) ? __( 'Order summary', 'woocommerce-subscriptions' ) : __( 'Subscription summary', 'woocommerce-subscriptions' ); |
| 37 | + echo wp_kses_post( $heading ); |
| 38 | + echo '<span>'; |
25 | 39 | } else {
|
26 |
| - // translators: $1-$3: opening and closing <a> tags $2: subscription's order number |
27 |
| - printf( esc_html_x( 'Subscription %1$s#%2$s%3$s', 'Used in email notification', 'woocommerce-subscriptions' ), '<a href="' . esc_url( $link_element_url ) . '">', esc_html( $order->get_order_number() ), '</a>' ); |
| 40 | + // Prior to the email improvements, the sub_heading was wrapped in square brackets. |
| 41 | + $id_heading = '[' . $id_heading . ']'; |
28 | 42 | }
|
| 43 | + |
| 44 | + echo wp_kses_post( |
| 45 | + sprintf( |
| 46 | + '%s%s%s (<time datetime="%s">%s</time>)', |
| 47 | + '<a class="link" href="' . esc_url( ( $sent_to_admin ) ? wcs_get_edit_post_link( $order->get_id() ) : $order->get_view_order_url() ) . '">', |
| 48 | + $id_heading, |
| 49 | + '</a>', |
| 50 | + $order->get_date_created()->format( 'c' ), |
| 51 | + wcs_format_datetime( $order->get_date_created() ) |
| 52 | + ) |
| 53 | + ); |
| 54 | + |
| 55 | + if ( $email_improvements_enabled ) { |
| 56 | + echo '</span>'; |
| 57 | + } |
| 58 | + |
29 | 59 | echo '</h2>';
|
30 | 60 | }
|
31 | 61 | ?>
|
32 |
| -<div style="margin-bottom: 40px;"> |
33 |
| - <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1"> |
| 62 | +<div style="margin-bottom: <?php echo $email_improvements_enabled ? '24px' : '40px'; ?>;"> |
| 63 | + <table class="td font-family <?php echo esc_attr( $order_table_class ); ?>" cellspacing="0" cellpadding="6" style="width: 100%;" border="1"> |
| 64 | + <?php if ( ! $email_improvements_enabled ) { ?> |
34 | 65 | <thead>
|
35 | 66 | <tr>
|
36 | 67 | <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo esc_html_x( 'Product', 'table headings in notification email', 'woocommerce-subscriptions' ); ?></th>
|
37 | 68 | <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo esc_html_x( 'Quantity', 'table headings in notification email', 'woocommerce-subscriptions' ); ?></th>
|
38 | 69 | <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo esc_html_x( 'Price', 'table headings in notification email', 'woocommerce-subscriptions' ); ?></th>
|
39 | 70 | </tr>
|
40 | 71 | </thead>
|
| 72 | + <?php } ?> |
41 | 73 | <tbody>
|
42 | 74 | <?php echo wp_kses_post( WC_Subscriptions_Email::email_order_items_table( $order, $order_items_table_args ) ); ?>
|
43 | 75 | </tbody>
|
44 | 76 | <tfoot>
|
45 | 77 | <?php
|
46 |
| - if ( $totals = $order->get_order_item_totals() ) { |
| 78 | + $item_totals = $order->get_order_item_totals(); |
| 79 | + $item_totals_count = count( $item_totals ); |
| 80 | + |
| 81 | + if ( $item_totals ) { |
47 | 82 | $i = 0;
|
48 |
| - foreach ( $totals as $total ) { |
| 83 | + foreach ( $item_totals as $total ) { |
49 | 84 | $i++;
|
| 85 | + $last_class = ( $i === $item_totals_count ) ? ' order-totals-last' : ''; |
50 | 86 | ?>
|
51 |
| - <tr> |
52 |
| - <th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php if ( 1 == $i ) { echo 'border-top-width: 4px;'; } ?>"><?php echo esc_html( $total['label'] ); ?></th> |
53 |
| - <td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php if ( 1 == $i ) { echo 'border-top-width: 4px;'; } ?>"><?php echo wp_kses_post( $total['value'] ); ?></td> |
| 87 | + <tr class="order-totals order-totals-<?php echo esc_attr( $total['type'] ?? 'unknown' ); ?><?php echo esc_attr( $last_class ); ?>"> |
| 88 | + <th class="td text-align-left" scope="row" colspan="2" style="<?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"> |
| 89 | + <?php |
| 90 | + echo wp_kses_post( $total['label'] ) . ' '; |
| 91 | + if ( $email_improvements_enabled ) { |
| 92 | + echo isset( $total['meta'] ) ? wp_kses_post( $total['meta'] ) : ''; |
| 93 | + } |
| 94 | + ?> |
| 95 | + </th> |
| 96 | + <td class="td text-align-<?php echo esc_attr( $order_total_text_align ); ?>" style="<?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['value'] ); ?></td> |
54 | 97 | </tr>
|
55 | 98 | <?php
|
56 | 99 | }
|
57 | 100 | }
|
58 | 101 | if ( $order->get_customer_note() ) {
|
59 |
| - ?> |
60 |
| - <tr> |
61 |
| - <th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Note:', 'woocommerce-subscriptions' ); ?></th> |
62 |
| - <td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo wp_kses_post( wptexturize( $order->get_customer_note() ) ); ?></td> |
63 |
| - </tr> |
64 |
| - <?php |
| 102 | + if ( $email_improvements_enabled ) { |
| 103 | + ?> |
| 104 | + <tr class="order-customer-note"> |
| 105 | + <td class="td text-align-left" colspan="3"> |
| 106 | + <b><?php esc_html_e( 'Customer note', 'woocommerce-subscriptions' ); ?></b><br> |
| 107 | + <?php echo wp_kses( nl2br( wptexturize( $order->get_customer_note() ) ), array( 'br' => array() ) ); ?> |
| 108 | + </td> |
| 109 | + </tr> |
| 110 | + <?php |
| 111 | + } else { |
| 112 | + ?> |
| 113 | + <tr> |
| 114 | + <th class="td text-align-left" scope="row" colspan="2"><?php esc_html_e( 'Note:', 'woocommerce-subscriptions' ); ?></th> |
| 115 | + <td class="td text-align-left"><?php echo wp_kses( nl2br( wptexturize( $order->get_customer_note() ) ), array() ); ?></td> |
| 116 | + </tr> |
| 117 | + <?php |
| 118 | + } |
65 | 119 | }
|
66 | 120 | ?>
|
67 | 121 | </tfoot>
|
|
0 commit comments