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 WooCommerce development the order customization is one of the most common tasks that you will undertake as a WooCommerce developer.
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 thanks 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 and 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
Conclusion
In this post, we have looked at the ways to get WooCommerce metadata and use this metadata in your WooCommerce plugin or theme.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Delete a Category in WordPress
- How to Create WooCommerce Storefront Child Theme [Complete Guide]
- How to Get Current User Role in WordPress & Display Roles
- How to Add Form To Product Page WooCommerce
- How to Add Select Field to Checkout WooCommerce
- How to Create Checkbox Field in WooCommerce Checkout Page
- How to Insert Data in Database in WordPress Using Ajax
- How to Display Category Names in WordPress Using a Practical Example
- How to Get Logged In User Information in WordPress
- How to Change Text in WooCommerce Email
- How to Delete a Page In WordPress
- How to Access WooCommerce Database
- How to Hide Customer Order Email For Free Orders WooCommerce
- How to Make WooCommerce Order Comments Required
- How to Get Product ID on Checkout Page Or Order Page In WooCommerce