Do you want to apply WooCommerce get order meta_data in your WooCommerce development but you cannot figure out how to get the WooCommerce order meta data? If this is the case, I will show you how to get the order meta data in WooCommerce without breaking a sweat!
In most cases, you want to customize the WooCommerce order to create several scenarios. In this post, I want to illustrate how to get order details in WooCommerce.
Woocommerce Get Order meta_data
For complete new WooCommerce developers, the term order meta can be difficult to understand. Let me begin by explaining what WooCommerce order meta data means.
If you place a WooCommerce order there are details that are associated with the WooCommerce order, these details are saved in the WordPress database.
If you want to understand how WooCommerce or WordPress database works, I wrote a comprehensive WordPress database tutorial that should guide you and take you from novice to an expert in WordPress database management.
WooCommerce Order Meta Data
When a customer placed an order from the WooCommerce store frontend, the order comes with a lot of details that include the customer’s details. In this case, the customer is redirected to the order received page as shown below :
On this order received page you will see the various order details and these are the meta data along with other details that may be saved as the meta data in the WordPress database.
You can also create a custom order received or WooCommerce thank you page using the WooCommerce Redirect after checkout plugin.
On the backend you can see the order meta data as shown on the image below :
How to Woocommerce Get Order meta_data
To get WooCommerce order meta data you may want to get the order object then access each of the details one by one using the appropriate WooCommerce method to get order meta data. The following is the various ways you apply WooCommerce get order meta data methods :
// Get an instance of the WC_Order object (same as before) $order = wc_get_order( $order_id ); $order_id = $order->get_id(); // Get the order ID $parent_id = $order->get_parent_id(); // Get the parent order ID (for subscriptions…) $user_id = $order->get_user_id(); // Get the costumer ID $user = $order->get_user(); // Get the WP_User object $order_status = $order->get_status(); // Get the order status $currency = $order->get_currency(); // Get the currency used $payment_method = $order->get_payment_method(); // Get the payment method ID $payment_title = $order->get_payment_method_title(); // Get the payment method title $date_created = $order->get_date_created(); // Get date created (WC_DateTime object) $date_modified = $order->get_date_modified(); // Get date modified (WC_DateTime object) $billing_country = $order->get_billing_country(); // Customer billing country
In this post, we have looked at the ways to get WooCommerce meta data and use this meta data in your WooCommerce plugin or theme.