Woo Dev Patch – Set a WooCommerce Order’s Paid Date Without Changing its Status

Small businesses often take orders through multiple mediums including offline. In such scenarios there may be a need to update a WooCommerce order’s paid date without updating its status.

You can do this with a small WooCommerce CRUD-based patch:

$order_id = 12345;
$now      = current_time( 'timestamp', true );

if ( $order_id > 0 ) {
	$order = wc_get_order( $order_id );
	if ( $order ) {
		$order->set_date_paid( $now );
		$order->save();
	}
}

Why this works

WooCommerce recommends using its CRUD methods for working with orders instead of directly modifying the database.

set_date_paid() updates the order’s paid date, while save() persists the change using WooCommerce’s order data store.

Using the WooCommerce CRUD methods also means the code doesn’t need to depend on the underlying database schema or worry about the active order storage system.

Common Mistake

Do not forget to call:

$order->save();

Without calling save(), the change remains only in the WC_Order object and isn’t persisted.

HPOS Compatibility

The snippet works on the legacy order storage system as well as the HPOS order storage system.

Tested with:

  • WordPress 7.1
  • WooCommerce 11.1.0

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top