After WooCommerce checkout, you can customize the order after the checkout to display the various order details or add more features to the order.
For you to customize the order or add new features to the order you need to know how you can get order details after checkout.
In this post, I will share with you briefly how you can get order details after checkout.
WooCommerce Get Order Details After Checkout
To get the order details after checkout you need to get the order ID after checkout and you can achieve this using the code snippet below :
global $wp; //Get Order ID $order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
After you get the order ID you can now obtain the order object and then loop through the order to get the items in the order as in the code snippet below :
// Get an instance of the WC_Order object $order = new WC_Order( $order_id ); $items = $order->get_items(); foreach ( $items as $key => $item ): //$product_id = $item['product_id']; $product = $item->get_product(); if ( $product ) { $productsInOrderIds[] = $product->get_id(); } return $productsInOrderIds; endforeach;
As you can see in the code above we have obtained the order details and the most important detail we need from the order is the products that are in the order.
We have used the get_items() function to get products in the order and we have gone ahead to obtain the products order IDs that we can repurpose in the code for more comparison as in the case of redirect after checkout based on the product in the order.
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 Add WooCommerce Checkout Default Country
- How to Check if a User is Logged In in WordPress
- How to Get WooCommerce Checkout Country Dropdown
- How to Hide the Weight of Product in WooCommerce
- How to Create One Product WooCommerce Storefront Store
- How to Create Custom Widget Area in WordPress Step by Step
- How to Simplify Checkout Free Items Storefront Theme
- 100+ Best Free WordPress Plugins By Popularity, Ratings & Users
- 30+ Best WordPress Anti-Spam Plugins for Total Spam Control
- How to Hide Price When Out of Stock In WooCommerce
- How to Get Product ID on the Checkout Page Or Order Page In WooCommerce
- How to Get Order ID on Checkout Page WooCommerce
- How to Hide Prices From Google In WooCommerce
- WooCommerce Storefront Theme Review
- How to Add Select Field to Checkout WooCommerce
- How to Hide Product Description Heading WooCommerce
- How to Redirect On Refresh WordPress Page » Detect Page Refresh PHP
- WooCommerce Storefront Show all Categories on the Homepage
- How to Hide Tax Label In WooCommerce