diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index db68ab9462e..b9b1ae3baec 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1475,22 +1475,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { } } - if ( $this->get_total() > 0 && $this->get_payment_method_title() ) { - $total_rows['payment_method'] = array( - 'label' => __( 'Payment method:', 'woocommerce' ), - 'value' => $this->get_payment_method_title(), - ); - } - - if ( $refunds = $this->get_refunds() ) { - foreach ( $refunds as $id => $refund ) { - $total_rows[ 'refund_' . $id ] = array( - 'label' => $refund->get_reason() ? $refund->get_reason() : __( 'Refund', 'woocommerce' ) . ':', - 'value' => wc_price( '-' . $refund->get_amount(), array( 'currency' => $this->get_currency() ) ), - ); - } - } - $total_rows['order_total'] = array( 'label' => __( 'Total:', 'woocommerce' ), 'value' => $this->get_formatted_order_total( $tax_display ), diff --git a/includes/class-wc-emails.php b/includes/class-wc-emails.php index 16c3ffdf0a7..2a41d27ae48 100644 --- a/includes/class-wc-emails.php +++ b/includes/class-wc-emails.php @@ -366,12 +366,15 @@ class WC_Emails { /** * Add customer details to email templates. * - * @param mixed $order + * @param WC_Order $order * @param bool $sent_to_admin (default: false) * @param bool $plain_text (default: false) * @return string */ public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) { + if ( ! is_a( 'WC_Order', $order ) ) { + return; + } $fields = array(); if ( $order->get_customer_note() ) { @@ -386,14 +389,14 @@ class WC_Emails { 'label' => __( 'Email address', 'woocommerce' ), 'value' => wptexturize( $order->get_billing_email() ), ); - } + } - if ( $order->get_billing_phone() ) { + if ( $order->get_billing_phone() ) { $fields['billing_phone'] = array( 'label' => __( 'Phone', 'woocommerce' ), 'value' => wptexturize( $order->get_billing_phone() ), ); - } + } $fields = array_filter( apply_filters( 'woocommerce_email_customer_details_fields', $fields, $sent_to_admin, $order ), array( $this, 'customer_detail_field_is_valid' ) ); @@ -408,6 +411,9 @@ class WC_Emails { * Get the email addresses. */ public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) { + if ( ! is_a( 'WC_Order', $order ) ) { + return; + } if ( $plain_text ) { wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order ) ); } else { diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index e9678490044..2811ec44884 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -1685,4 +1685,35 @@ class WC_Order extends WC_Abstract_Order { public function get_remaining_refund_items() { return absint( $this->get_item_count() - $this->get_item_count_refunded() ); } + + /** + * Get totals for display on pages and in emails. + * + * @param mixed $tax_display + * @return array + */ + public function get_order_item_totals( $tax_display = '' ) { + $total_rows = parent::get_order_item_totals( $tax_display ); + $total_row = array_pop( $total_rows ); + + if ( $this->get_total() > 0 && $this->get_payment_method_title() ) { + $total_rows['payment_method'] = array( + 'label' => __( 'Payment method:', 'woocommerce' ), + 'value' => $this->get_payment_method_title(), + ); + } + + if ( $refunds = $this->get_refunds() ) { + foreach ( $refunds as $id => $refund ) { + $total_rows[ 'refund_' . $id ] = array( + 'label' => $refund->get_reason() ? $refund->get_reason() : __( 'Refund', 'woocommerce' ) . ':', + 'value' => wc_price( '-' . $refund->get_amount(), array( 'currency' => $this->get_currency() ) ), + ); + } + } + + $total_rows['order_total'] = $total_row; + + return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this ); + } } diff --git a/includes/class-wc-structured-data.php b/includes/class-wc-structured-data.php index 504427b6364..bac68582478 100644 --- a/includes/class-wc-structured-data.php +++ b/includes/class-wc-structured-data.php @@ -328,7 +328,7 @@ class WC_Structured_Data { * @param bool $plain_text Plain text email (default: false). */ public function generate_order_data( $order, $sent_to_admin = false, $plain_text = false ) { - if ( $plain_text ) { + if ( $plain_text || ! is_a( $order, 'WC_Order' ) ) { return; }