WC_Admin_List_Table_Orders::order_preview_get_order_details
Get order details to send to the ajax endpoint for previews.
Method of the class: WC_Admin_List_Table_Orders{}
Hooks from the method
Returns
Array.
Usage
$result = WC_Admin_List_Table_Orders::order_preview_get_order_details( $order );
- $order(WC_Order) (required)
- Order object.
WC_Admin_List_Table_Orders::order_preview_get_order_details() WC Admin List Table Orders::order preview get order details code WC 10.6.2
public static function order_preview_get_order_details( $order ) {
if ( ! $order ) {
return array();
}
$payment_via = $order->get_payment_method_title();
$payment_method = $order->get_payment_method();
$payment_gateways = WC()->payment_gateways() ? WC()->payment_gateways->payment_gateways() : array();
$transaction_id = $order->get_transaction_id();
if ( $transaction_id ) {
$url = isset( $payment_gateways[ $payment_method ] ) ? $payment_gateways[ $payment_method ]->get_transaction_url( $order ) : false;
if ( $url ) {
$payment_via .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
} else {
$payment_via .= ' (' . esc_html( $transaction_id ) . ')';
}
}
$billing_address = $order->get_formatted_billing_address();
$shipping_address = $order->get_formatted_shipping_address();
$wp_post_type = get_post_type_object( $order->get_type() ) ?? get_post_type_object( 'shop_order' );
$is_editable = current_user_can( $wp_post_type->cap->edit_post, $order->get_id() );
// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
/**
* Filter to customize the order details data that the woocommerce_get_order_details action will send.
*
* @param array $order_details Order details.
*/
$order_details = apply_filters(
'woocommerce_admin_order_preview_get_order_details',
array(
'data' => $order->get_data(),
'is_editable' => $is_editable,
'order_number' => $order->get_order_number(),
'item_html' => self::get_order_preview_item_html( $order ),
'actions_html' => self::get_order_preview_actions_html( $order ),
'ship_to_billing' => wc_ship_to_billing_address_only(),
'needs_shipping' => $order->needs_shipping_address(),
'formatted_billing_address' => $billing_address ? $billing_address : __( 'N/A', 'woocommerce' ),
'formatted_shipping_address' => $shipping_address ? $shipping_address : __( 'N/A', 'woocommerce' ),
'shipping_address_map_url' => $order->get_shipping_address_map_url(),
'payment_via' => $payment_via,
'shipping_via' => $order->get_shipping_method(),
'status' => $order->get_status(),
'status_name' => wc_get_order_status_name( $order->get_status() ),
),
$order
);
// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
$order_details['data'] = array_intersect_key( $order_details['data'], array_flip( array( 'id', 'billing', 'shipping', 'customer_note' ) ) );
return $order_details;
}