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.
Returns
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_Abstract_Order) (required)
- The order to get the data from.
ReceiptRenderingEngine::get_order_data() ReceiptRenderingEngine::get order data code WC 10.8.1
private function get_order_data( WC_Abstract_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( OrderItemType::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' => OrderItemType::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 ),
);
}
$is_order_failed = $order->has_status( 'failed' );
$line_items_info[] = array(
'type' => 'amount_paid',
'title' => $is_order_failed ? __( 'Amount', 'woocommerce' ) : __( 'Amount Paid', 'woocommerce' ),
'amount' => wc_price( $order->get_total(), $get_price_args ),
);
$payment_info = $this->get_woo_pay_data( $order );
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' => $is_order_failed ? __( 'Order Total', 'woocommerce' ) : __( 'Amount Paid', 'woocommerce' ),
'date_paid_section_title' => $is_order_failed ? __( 'Order Date', 'woocommerce' ) : __( 'Date Paid', 'woocommerce' ),
'payment_method_section_title' => __( 'Payment method', 'woocommerce' ),
'payment_status_section_title' => __( 'Payment status', 'woocommerce' ),
'payment_status' => $is_order_failed ? __( 'Failed', 'woocommerce' ) : __( 'Success', '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() ?? $order->get_date_created() ),
'line_items' => $line_items_info,
'payment_method' => $order->get_payment_method_title(),
'show_payment_method_title' => empty( $payment_info['card_last4'] ) && empty( $payment_info['brand'] ),
'notes' => array_map( 'get_comment_text', $order->get_customer_order_notes() ),
'payment_info' => $payment_info,
);
}