Automattic\WooCommerce\Internal\ReceiptRendering
ReceiptRenderingEngine::get_order_data() │ private │ WC 1.0
Get the order data that the receipt template will use.
Method of the class: ReceiptRenderingEngine{}
No Hooks.
Return
Array
. The order data as an associative array.
Usage
// private - for code of main (parent) class only $result = $this->get_order_data( $order ): array;
- $order(WC_Order) (required)
- The order to get the data from.
ReceiptRenderingEngine::get_order_data() ReceiptRenderingEngine::get order data code WC 9.3.3
private function get_order_data( WC_Order $order ): array { $store_name = get_bloginfo( 'name' ); if ( $store_name ) { /* translators: %s = store name */ $receipt_title = sprintf( __( 'Receipt from %s', 'woocommerce' ), $store_name ); } else { $receipt_title = __( 'Receipt', 'woocommerce' ); } $order_id = $order->get_id(); if ( $order_id ) { /* translators: %d = order id */ $summary_title = sprintf( __( 'Summary: Order #%d', 'woocommerce' ), $order->get_id() ); } else { $summary_title = __( 'Summary', 'woocommerce' ); } $get_price_args = array( 'currency' => $order->get_currency() ); $line_items_info = array(); $line_items = $order->get_items( 'line_item' ); foreach ( $line_items as $line_item ) { $line_item_product = $line_item->get_product(); if ( false === $line_item_product ) { $line_item_title = $line_item->get_name(); } else { $line_item_title = ( $line_item_product instanceof \WC_Product_Variation ) ? ( wc_get_product( $line_item_product->get_parent_id() )->get_name() ) . '. ' . $line_item_product->get_attribute_summary() : $line_item_product->get_name(); } $line_items_info[] = array( 'type' => 'product', 'item' => $line_item, 'title' => wp_kses( $line_item_title, array() ), 'quantity' => $line_item->get_quantity(), 'amount' => wc_price( $line_item->get_subtotal(), $get_price_args ), ); } $line_items_info[] = array( 'type' => 'subtotal', 'title' => __( 'Subtotal', 'woocommerce' ), 'amount' => wc_price( $order->get_subtotal(), $get_price_args ), ); $coupon_names = ArrayUtil::select( $order->get_coupons(), 'get_name', ArrayUtil::SELECT_BY_OBJECT_METHOD ); if ( ! empty( $coupon_names ) ) { $line_items_info[] = array( 'type' => 'discount', /* translators: %s = comma-separated list of coupon codes */ 'title' => sprintf( __( 'Discount (%s)', 'woocommerce' ), join( ', ', $coupon_names ) ), 'amount' => wc_price( -$order->get_total_discount(), $get_price_args ), ); } foreach ( $order->get_fees() as $fee ) { $name = $fee->get_name(); $line_items_info[] = array( 'type' => 'fee', 'title' => '' === $name ? __( 'Fee', 'woocommerce' ) : $name, 'amount' => wc_price( $fee->get_total(), $get_price_args ), ); } $shipping_total = (float) $order->get_shipping_total(); if ( $shipping_total ) { $line_items_info[] = array( 'type' => 'shipping_total', 'title' => __( 'Shipping', 'woocommerce' ), 'amount' => wc_price( $order->get_shipping_total(), $get_price_args ), ); } $total_taxes = 0; foreach ( $order->get_taxes() as $tax ) { $total_taxes += (float) $tax->get_tax_total() + (float) $tax->get_shipping_tax_total(); } if ( $total_taxes ) { $line_items_info[] = array( 'type' => 'taxes_total', 'title' => __( 'Taxes', 'woocommerce' ), 'amount' => wc_price( $total_taxes, $get_price_args ), ); } $line_items_info[] = array( 'type' => 'amount_paid', 'title' => __( 'Amount Paid', 'woocommerce' ), 'amount' => wc_price( $order->get_total(), $get_price_args ), ); return array( 'order' => $order, 'constants' => array( 'font_size' => self::FONT_SIZE, 'margin' => self::MARGIN, 'title_font_size' => self::TITLE_FONT_SIZE, 'footer_font_size' => self::FOOTER_FONT_SIZE, 'line_height' => self::LINE_HEIGHT, 'icon_height' => self::ICON_HEIGHT, 'icon_width' => self::ICON_WIDTH, ), 'texts' => array( 'receipt_title' => $receipt_title, 'amount_paid_section_title' => __( 'Amount Paid', 'woocommerce' ), 'date_paid_section_title' => __( 'Date Paid', 'woocommerce' ), 'payment_method_section_title' => __( 'Payment method', 'woocommerce' ), 'summary_section_title' => $summary_title, 'order_notes_section_title' => __( 'Notes', 'woocommerce' ), 'app_name' => __( 'Application Name', 'woocommerce' ), 'aid' => __( 'AID', 'woocommerce' ), 'account_type' => __( 'Account Type', 'woocommerce' ), ), 'formatted_amount' => wc_price( $order->get_total(), $get_price_args ), 'formatted_date' => wc_format_datetime( $order->get_date_paid() ), 'line_items' => $line_items_info, 'payment_method' => $order->get_payment_method_title(), 'notes' => array_map( 'get_comment_text', $order->get_customer_order_notes() ), 'payment_info' => $this->get_woo_pay_data( $order ), ); }