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.
Метод класса: OrdersTableDataStore{}
Возвращает
true|false
. Whether the modified date needs to be updated.
Использование
// private - только в коде основоного (родительского) класса $result = $this->should_save_after_meta_change( $order, $meta );
- $order(WC_Order) (обязательный)
- Order object.
- $meta(\WC_Meta_Data|null)
- Metadata object.
По умолчанию: null
Код OrdersTableDataStore::should_save_after_meta_change() OrdersTableDataStore::should save after meta change WC 9.3.3
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_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 ); }