How to Get Purchase Date From Woocommerce Order?

6 minutes read

To get the purchase date from a WooCommerce order, you can retrieve the order's meta data using the order ID. The purchase date is stored in the order's meta data under the key '_completed_date'. You can use the get_post_meta() function to retrieve this information. Simply pass the order ID and the key '_completed_date' as parameters to get the purchase date. This will return the date and time when the order was completed.

Best WooCommerce Cloud Hosting Providers of July 2024

1
Vultr

Rating is 5 out of 5

Vultr

  • Ultra-fast Intel Core
  • High Performance and Cheap Cloud Dedicated Servers
  • 1 click install Wordpress
  • Low Price and High Quality
2
Digital Ocean

Rating is 5 out of 5

Digital Ocean

  • Active Digital Community
  • Simple Control Panel
  • Starting from 5$ per month
3
AWS

Rating is 5 out of 5

AWS

4
Cloudways

Rating is 5 out of 5

Cloudways


How to retrieve purchase date using WooCommerce API?

To retrieve the purchase date using the WooCommerce API, you can make a GET request to the "orders" endpoint. Here is an example of how you can do this:

  1. Generate API keys: First, you need to generate API keys for your WooCommerce store. You can do this by going to WooCommerce > Settings > Advanced > REST API in your WordPress admin dashboard.
  2. Make a GET request: Use a tool like Postman or cURL to make a GET request to the "orders" endpoint of the WooCommerce API. You will need to include your API keys in the request headers.


For example, if your WooCommerce store URL is "https://yourstore.com" and your API keys are "consumer_key" and "consumer_secret", you can make a request like this:

1
2
3
GET https://yourstore.com/wp-json/wc/v3/orders
Headers:
- Authorization: Basic base64(consumer_key:consumer_secret)


  1. Filter the response: In the response data, you will see details of all orders placed on your WooCommerce store, including the purchase date. You can parse the response data to extract the purchase date for each order.


By following these steps, you can retrieve the purchase date using the WooCommerce API.


How to access purchase date in WooCommerce order details page?

To access the purchase date in the WooCommerce order details page, you can use the following code snippet:

1
2
3
4
5
global $post;
$order = wc_get_order( $post->ID );
$purchase_date = $order->get_date_created();

echo 'Purchase Date: ' . $purchase_date->format('F j, Y');


You can place this code in your theme's functions.php file or in a custom plugin. This code gets the order object using the post ID of the current order details page and then retrieves the purchase date using the get_date_created() method. Finally, the purchase date is formatted and displayed on the order details page.


How to retrieve purchase date from WooCommerce order?

To retrieve the purchase date from a WooCommerce order, you can use the following code snippet:

1
2
3
4
5
6
$order = wc_get_order( $order_id );

if ( $order ) {
    $purchase_date = $order->get_date_created(); // Retrieve the purchase date/time
    echo 'Purchase Date: ' . $purchase_date->date_i18n(); // Format the purchase date/time
}


Replace $order_id with the order ID you want to retrieve the purchase date from. This code snippet will fetch the purchase date/time of the specified order and format it in a human-readable format.


What is the function to retrieve purchase date from WooCommerce order?

To retrieve the purchase date from a WooCommerce order, you can use the following function:

1
2
3
4
$order_id = 123; // Replace 123 with the actual order ID
$order = wc_get_order( $order_id );
$purchase_date = $order->get_date_created();
echo $purchase_date->date_i18n( 'Y-m-d H:i:s' ); 


This code snippet retrieves the purchase date of the order with ID 123 and then formats it to display in a specific date and time format (in this case, 'Y-m-d H:i:s'). You can replace the order ID with the actual order ID that you want to retrieve the purchase date for.


How to find purchase date in a WooCommerce order?

In WooCommerce, you can find the purchase date of an order by following these steps:

  1. Log in to your WordPress admin dashboard.
  2. Go to WooCommerce > Orders.
  3. Find and click on the order for which you want to see the purchase date.
  4. In the order details page, you should see the purchase date in the "Order Date" field.


If you are looking to retrieve the purchase date programmatically, you can do so by accessing the order object and using the get_date_created() method. Here's an example code snippet to retrieve the purchase date of an order:

1
2
3
4
$order = wc_get_order( $order_id );
$purchase_date = $order->get_date_created();

echo 'Purchase Date: ' . $purchase_date->date_i18n( get_option( 'date_format' ) );


This code snippet retrieves the purchase date of the order with the ID $order_id and then formats it according to the date format set in your WordPress settings.


By following these steps, you should be able to easily find the purchase date of an order in WooCommerce.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To get the order date in WooCommerce, you can use the following code snippet:$order = wc_get_order( $order_id ); $order_date = $order->get_date_created();This code retrieves the order object using the order ID and then gets the created date of the order. Yo...
To know when an order gets open in WooCommerce, you can check the order details in the backend of your WooCommerce store. The date and time when the order was placed will be recorded in the order information. You can view this information by going to the WooCo...
In WooCommerce, you can retrieve the order price by using the order object. You can get the order object by using the order ID or order number. Once you have the order object, you can use the get_total method to get the total price of the order. Alternatively,...