From edce5277e5f038cd8bdeb0c6612c2a079b92f881 Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Sat, 18 May 2019 15:43:04 +0200 Subject: [PATCH 1/4] check if product exists before calling get_sku() --- templates/emails/plain/email-order-items.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/templates/emails/plain/email-order-items.php b/templates/emails/plain/email-order-items.php index 8392ec0ccc7..03d08ca73c1 100644 --- a/templates/emails/plain/email-order-items.php +++ b/templates/emails/plain/email-order-items.php @@ -12,7 +12,7 @@ * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce/Templates/Emails/Plain - * @version 3.2.0 + * @version 3.6.4 */ if ( ! defined( 'ABSPATH' ) ) { @@ -22,9 +22,15 @@ if ( ! defined( 'ABSPATH' ) ) { foreach ( $items as $item_id => $item ) : if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) { $product = $item->get_product(); + + if ( is_object( $product ) ) { + $sku = $product->get_sku(); + $purchase_note = $product->get_purchase_note(); + } + echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); - if ( $show_sku && $product->get_sku() ) { - echo ' (#' . $product->get_sku() . ')'; + if ( $show_sku && !empty( $sku ) ) { + echo ' (#' . $sku . ')'; } echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item ); echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n"; @@ -43,7 +49,7 @@ foreach ( $items as $item_id => $item ) : do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text ); } // Note - if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = $product->get_purchase_note() ) ) { + if ( $show_purchase_note && !empty( $purchase_note ) ) ) { echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) ); } echo "\n\n"; From 3819350aaaafddb1df14bc9be68820df619ee75f Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Sat, 18 May 2019 15:51:18 +0200 Subject: [PATCH 2/4] remove stray parenthesis --- templates/emails/plain/email-order-items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/emails/plain/email-order-items.php b/templates/emails/plain/email-order-items.php index 03d08ca73c1..caa23378db8 100644 --- a/templates/emails/plain/email-order-items.php +++ b/templates/emails/plain/email-order-items.php @@ -49,7 +49,7 @@ foreach ( $items as $item_id => $item ) : do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text ); } // Note - if ( $show_purchase_note && !empty( $purchase_note ) ) ) { + if ( $show_purchase_note && !empty( $purchase_note ) ) { echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) ); } echo "\n\n"; From 5089c93969b6d52c6ee952da6c67285de2a374ce Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Sat, 18 May 2019 16:36:34 +0200 Subject: [PATCH 3/4] coding standards --- templates/emails/plain/email-order-items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/emails/plain/email-order-items.php b/templates/emails/plain/email-order-items.php index caa23378db8..cb09df7e5aa 100644 --- a/templates/emails/plain/email-order-items.php +++ b/templates/emails/plain/email-order-items.php @@ -29,7 +29,7 @@ foreach ( $items as $item_id => $item ) : } echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); - if ( $show_sku && !empty( $sku ) ) { + if ( $show_sku && ! empty( $sku ) ) { echo ' (#' . $sku . ')'; } echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item ); @@ -49,7 +49,7 @@ foreach ( $items as $item_id => $item ) : do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text ); } // Note - if ( $show_purchase_note && !empty( $purchase_note ) ) { + if ( $show_purchase_note && ! empty( $purchase_note ) ) { echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) ); } echo "\n\n"; From aee539e0346ac34ad1b28a5849132cf978e9a8a1 Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Tue, 21 May 2019 09:18:45 +0200 Subject: [PATCH 4/4] declare plain text email variables --- templates/emails/plain/email-order-items.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/emails/plain/email-order-items.php b/templates/emails/plain/email-order-items.php index cb09df7e5aa..511edd91677 100644 --- a/templates/emails/plain/email-order-items.php +++ b/templates/emails/plain/email-order-items.php @@ -12,7 +12,7 @@ * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce/Templates/Emails/Plain - * @version 3.6.4 + * @version 3.7.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -22,6 +22,8 @@ if ( ! defined( 'ABSPATH' ) ) { foreach ( $items as $item_id => $item ) : if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) { $product = $item->get_product(); + $sku = ''; + $purchase_note = ''; if ( is_object( $product ) ) { $sku = $product->get_sku(); @@ -29,7 +31,7 @@ foreach ( $items as $item_id => $item ) : } echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); - if ( $show_sku && ! empty( $sku ) ) { + if ( $show_sku && $sku ) { echo ' (#' . $sku . ')'; } echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item ); @@ -49,7 +51,7 @@ foreach ( $items as $item_id => $item ) : do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text ); } // Note - if ( $show_purchase_note && ! empty( $purchase_note ) ) { + if ( $show_purchase_note && $purchase_note ) { echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) ); } echo "\n\n";