Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::should_save_after_meta_change
Helper function to check whether the modified date needs to be updated after a meta save.
This method prevents order->save() call multiple times in the same request after any meta update by checking if:
- Order modified date is already the current date, no updates needed in this case.
- If there are changes already queued for order object, then we don't need to update the modified date as it will be updated ina subsequent save() call.
Method of the class: OrdersTableDataStore{}
Hooks from the method
Returns
true|false. Whether the modified date needs to be updated.
Usage
// private - for code of main (parent) class only $result = $this->should_save_after_meta_change( $order, $meta );
- $order(WC_Order) (required)
- Order object.
- $meta(WC_Meta_Data|null)
- Metadata object.
Default:null
OrdersTableDataStore::should_save_after_meta_change() OrdersTableDataStore::should save after meta change code WC 10.7.0
private function should_save_after_meta_change( $order, $meta = null ) {
$current_time = $this->legacy_proxy->call_function( 'current_time', 'mysql', 1 );
$current_date_time = new \WC_DateTime( $current_time, new \DateTimeZone( 'GMT' ) );
$should_save =
$order->get_id() > 0
&& ! isset( self::$sync_on_read_order_ids[ $order->get_id() ] )
&& $order->get_date_modified() < $current_date_time && empty( $order->get_changes() )
&& ( ! is_object( $meta ) || ! in_array( $meta->key, $this->ephemeral_meta_keys, true ) );
/**
* Allows code to skip a full order save() when metadata is changed.
*
* @since 8.8.0
*
* @param bool $should_save Whether to trigger a full save after metadata is changed.
*/
return apply_filters( 'woocommerce_orders_table_datastore_should_save_after_meta_change', $should_save );
}