How to get purchase date from woocommerce order?

Member

by addison , in category: PHP CMS , 13 days ago

How to get purchase date from woocommerce order?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 12 days ago

@addison 

To get the purchase date from a WooCommerce order, you can use the following code snippet in your theme's functions.php file or in a plugin:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function get_purchase_date_from_order($order_id) {
    $order = wc_get_order($order_id);
    
    if ($order) {
        $purchase_date = $order->get_date_created();
        
        if ($purchase_date) {
            return $purchase_date->date('Y-m-d H:i:s');
        }
    }
    
    return false;
}


You can then use this function by passing the order ID as a parameter to retrieve the purchase date in a formatted string.