A Programmer’s Guide to Getting Order Info from the $order Object in WooCommerce

As a programmer, you may often find yourself working with the $order object in WooCommerce. This object contains information about the order, such as the customer’s name, the products ordered, and the shipping address. In this article, we’ll discuss how to get order info from the $order object, including different methods you can use to access specific pieces of information.

First, let’s take a look at the structure of the $order object. The $order object is an instance of the WC_Order class, which contains various properties and methods that you can use to access order information. Some of the most commonly used properties of the $order object include:


$order = wc_get_order($order_id);
/*
 * Methods for getting data from the order object.
 */
// Get the unique ID for this order.
$order->get_id();
// Get order key.
$order->get_order_key();
//Gets the order number for display (by default, order ID).
$order->get_order_number();
// Get basic order data in array format.
$order->get_base_data();
// Get parent order ID.
$order->get_parent_id();
// Get all class data in array format.
$order->get_data();
// Get customer_id
$order->get_customer_id();
$order->get_user_id();
// Get customer ip address.
$order->get_customer_ip_address();
// Get customer user agent.
$order->get_customer_user_agent();
// Get the user associated with the order. False for guests.
$order->get_user();
// Get billing first name.
$order->get_billing_first_name();
// Get billing last name.
$order->get_billing_last_name();
// Get a formatted billing full name.
$order->get_formatted_billing_full_name();
// Get billing company.
$order->get_billing_company();
// Get billing address line 1.
$order->get_billing_address_1();
// Get billing address line 2.
$order->get_billing_address_2();
// Get billing city.
$order->get_billing_city();
// Get billing state.
$order->get_billing_state();
// Get billing postcode.
$order->get_billing_postcode();
// Get billing country.
$order->get_billing_country();
// Get a formatted billing address for the order.
$order->get_formatted_billing_address();
// Get billing email.
$order->get_billing_email();
// Get billing phone.
$order->get_billing_phone();
// Get shipping first name.
$order->get_shipping_first_name();
// Get shipping last name.
$order->get_shipping_last_name();
// Get a formatted shipping full name.
$order->get_formatted_shipping_full_name();
// Get shipping company.
$order->get_shipping_company();
// Get shipping address line 1.
$order->get_shipping_address_1();
// Get shipping address line 2.
$order->get_shipping_address_2();
// Get shipping city.
$order->get_shipping_city();
// Get shipping state.
$order->get_shipping_state();
// Get shipping postcode.
$order->get_shipping_postcode();
// Get shipping country.
$order->get_shipping_country();
// Get a formatted shipping address for the order.
$order->get_formatted_shipping_address();
// Get shipping phone.
$order->get_shipping_phone();
// Gets formatted shipping method title.
$order->get_shipping_method();
// Get the payment method.
$order->get_payment_method();
// Get the payment method title.
$order->get_payment_method_title();
// Get transaction d.
$order->get_transaction_id();
// Get created via.
$order->get_created_via();
// Get customer note.
$order->get_customer_note();
// Get date completed.
$order->get_date_completed();
// Get date paid.
$order->get_date_paid();
// Get cart hash.
$order->get_cart_hash();
// Gets the requested address in raw, non-formatted way.
$order->get_address();
// Get a formatted shipping address for the order.
$order->get_shipping_address_map_url();
// Gets information about whether stock was reduced.
$order->get_order_stock_reduced();
// Gets information about whether permissions were generated yet.
$order->get_download_permissions_granted();
// Whether email have been sent for this order.
$order->get_new_order_email_sent();
// Gets information about whether sales were recorded.
$order->get_recorded_sales();
// Get downloads from all line items for this order.
$order->get_downloadable_items();
/*
 *  URLs and Endpoints
 */
// Generates a URL so that a customer can pay for their (unpaid - pending) order.
// Pass 'true' for the checkout version which doesn't offer gateway choices.
$order->get_checkout_payment_url();
// Generates a URL for the thanks page (order received)
$order->get_checkout_order_received_url();
// Generates a URL so that a customer can cancel their (unpaid - pending) order.
$order->get_cancel_order_url();
// Generates a URL to view an order from my account page.
$order->get_view_order_url();
// Gets the URL to edit the order in the backend.
$order->get_edit_order_url();
// List order notes (public) for the customer.
$order->get_customer_order_notes();
/*
 *  Refunds
 */
// Get order refunds.
$order->get_refunds();
// Get amount already refunded.
$order->get_total_refunded();
// Get the total tax refunded.
$order->get_total_tax_refunded();
// Get the total shipping refunded.
$order->get_total_shipping_refunded();
// Gets the count of order items of a certain type that have been refunded.
$order->get_item_count_refunded();
// Get the total number of items refunded.
$order->get_total_qty_refunded();
// Get the refunded amount for a line item.
$order->get_qty_refunded_for_item($item_id);
// Get the refunded amount for a line item.
$order->get_total_refunded_for_item($item_id);
// Get the refunded tax amount for a line item.
$order->get_tax_refunded_for_item($item_id, $tax_id);
// Get total tax refunded by rate ID.
$order->get_total_tax_refunded_by_rate_id($rate_id);
// How much money is left to refund?
$order->get_remaining_refund_amount();
// How many items are left to refund?
$order->get_remaining_refund_items();
// Get totals for display on pages and in emails.
$order->get_order_item_totals();
/*
 *  Prices
 */
// Gets order currency.
$order->get_currency();
// Get prices_include_tax.
$order->get_prices_include_tax();
// G Get discount_total.
$order->get_discount_total();
// Get discount_total.
$order->get_discount_tax();
// Get shipping_total.
$order->get_shipping_total();
// Get shipping_tax.
$order->get_shipping_tax();
// Gets order grand total including taxes, shipping cost, fees, and coupon discounts. Used in gateways.
$order->get_total();
// Get total tax amount. Alias for get_order_tax().
$order->get_total_tax();
// Gets the total discount amount.
$order->get_total_discount();
// Gets order subtotal. Order subtotal is the price of all items excluding taxes, fees, shipping cost, and coupon discounts.
// If sale price is set on an item, the subtotal will include this sale discount. E.g. a product with a regular
// price of $100 bought at a 50% discount will represent $50 of the subtotal for the order.
$order->get_subtotal();
// Get taxes, merged by code, formatted ready for output.
$order->get_tax_totals();

// Return an array of fees within this order.
$order->get_fees();
// Return an array of taxes within this order.
$order->get_taxes();
// Return an array of coupons within this order.
$order->get_coupons();
// Get used coupon codes only.
$order->get_coupon_codes();
// Gets the count of order items of a certain type.
$order->get_item_count();

// Get date_created.
$order->get_date_created();
// Get date_modified.
$order->get_date_modified();
// Get date_paid.
$order->get_date_paid();
// Get date_modified.
$order->get_date_completed();
// Get the order statuses without wc- internal prefix.
$order->get_status();

/*
 *  Order Items
 */
foreach ( $order->get_items() as $item_id => $item ) {
	//Get order ID this meta belongs to.
	$item->get_order_id();
	// Get parent order object.
	$item->get_order();
	// Get order item name.
	$item->get_name();
	// Get order item type. Overridden by child classes.
	$item->get_type();
	// Get the associated product.
	$item->get_product();
	// Get product ID.
	$item->get_product_id();
	//  Get variation ID.
	$item->get_variation_id();
	// Get quantity
	$item->get_quantity();
	// Get tax status.
	$item->get_tax_status();
	//Get tax class.
	$item->get_tax_class();
	// Get total.
	$item->get_total();
	// Get total tax.
	$item->get_total_tax();
	//Get subtotal.
	$item->get_subtotal();
	// Get subtotal tax.
	$item->get_subtotal_tax();
	// Get All Meta Data.
	$item->get_meta_data();
	// Get custom meta data
	$item->get_meta( '_custom', true );
}

Leave a Comment

Your email address will not be published. Required fields are marked *