WC_Order_Data_Store_CPT::update()publicWC 1.0

Method to update an order in the database.

Method of the class: WC_Order_Data_Store_CPT{}

Return

null. Nothing (null).

Usage

$WC_Order_Data_Store_CPT = new WC_Order_Data_Store_CPT();
$WC_Order_Data_Store_CPT->update( $order );
$order(WC_Order) (required) (passed by reference — &)
Order object.

WC_Order_Data_Store_CPT::update() code WC 9.4.2

public function update( &$order ) {
	// 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 ) ) ) {
		$order->set_date_paid( $order->get_date_created( 'edit' ) );
	}

	// Also grab the current status so we can compare.
	$previous_status = get_post_status( $order->get_id() );
	// If the order doesn't exist in the DB, we will consider it as new.
	if ( ! $previous_status && $order->get_id() === 0 ) {
		$previous_status = 'new';
	}

	// Update the order.
	parent::update( $order );

	$current_status = $order->get_status( 'edit' );

	// We need to remove the wc- prefix from the status for comparison and proper evaluation of new vs updated orders.
	$previous_status = OrderUtil::remove_status_prefix( $previous_status );
	$current_status  = OrderUtil::remove_status_prefix( $current_status );

	$draft_statuses = array( 'new', 'auto-draft', 'draft', 'checkout-draft' );

	// This hook should be fired only if the new status is not one of draft statuses and the previous status was one of the draft statuses.
	if (
		$current_status !== $previous_status
		&& ! in_array( $current_status, $draft_statuses, true )
		&& in_array( $previous_status, $draft_statuses, true )
	) {
		do_action( 'woocommerce_new_order', $order->get_id(), $order );  // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
		return;
	}

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