Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::update()publicWC 1.0

Method to update an order in the database.

Метод класса: OrdersTableDataStore{}

Возвращает

null. Ничего (null).

Использование

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->update( $order );
$order(\WC_Order) (обязательный) (передается по ссылке — &)
Order object.

Код OrdersTableDataStore::update() WC 8.7.0

public function update( &$order ) {
	$previous_status = ArrayUtil::get_value_or_default( $order->get_data(), 'status' );
	$changes         = $order->get_changes();

	// Before updating, ensure date paid is set if missing.
	if (
		! $order->get_date_paid( 'edit' )
		&& version_compare( $order->get_version( 'edit' ), '3.0', '<' )
		&& $order->has_status( apply_filters( 'woocommerce_payment_complete_order_status', $order->needs_processing() ? 'processing' : 'completed', $order->get_id(), $order ) ) // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
	) {
		$order->set_date_paid( $order->get_date_created( 'edit' ) );
	}

	if ( null === $order->get_date_created( 'edit' ) ) {
		$order->set_date_created( time() );
	}

	$order->set_version( Constants::get_constant( 'WC_VERSION' ) );

	// Fetch changes.
	$changes = $order->get_changes();
	$this->persist_updates( $order );

	// Update download permissions if necessary.
	if ( array_key_exists( 'billing_email', $changes ) || array_key_exists( 'customer_id', $changes ) ) {
		$data_store = \WC_Data_Store::load( 'customer-download' );
		$data_store->update_user_by_order_id( $order->get_id(), $order->get_customer_id(), $order->get_billing_email() );
	}

	// Mark user account as active.
	if ( array_key_exists( 'customer_id', $changes ) ) {
		wc_update_user_last_active( $order->get_customer_id() );
	}

	$order->apply_changes();
	$this->clear_caches( $order );

	// For backwards compatibility, moving an auto-draft order to a valid status triggers the 'woocommerce_new_order' hook.
	if ( ! empty( $changes['status'] ) && 'auto-draft' === $previous_status ) {
		do_action( 'woocommerce_new_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
		return;
	}

	// For backwards compat with CPT, trashing/untrashing and changing previously datastore-level props does not trigger the update hook.
	if ( ( ! empty( $changes['status'] ) && in_array( 'trash', array( $changes['status'], $previous_status ), true ) )
		|| ( ! empty( $changes ) && ! array_diff_key( $changes, array_flip( $this->get_post_data_store_for_backfill()->get_internal_data_store_key_getters() ) ) ) ) {
		return;
	}

	do_action( 'woocommerce_update_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
}