A Step by Step Guide to Changing Order Number in Magento 2

A Step by Step Guide to Changing Order Number in Magento 2

Magento 2 generates the order number or order ID automatically. If you wish to change it, the process is not so straightforward. The reason is that altering the order number can impact other store functionality as they are interrelated. Most users who change the ID complain about problems with order tracking, reporting, and other inconsistencies.

If you still wish to know how to change the order ID, we recommend proceeding with caution. However, with our step by step guide, the risk of something going wrong is minimal. Before we list the ways through which you can change the order number, let’s briefly touch upon why you may need to do so.

Why Change the Default Magento 2 Order Number?

As stated above, changing the default order number in Magento 2 is not a common or recommended practice. Nevertheless, there could be some scenarios or reasons why a Magento admin might want to consider changing the default order number. Let’s go through these reasons.

  • Compliance
  • One of the reasons that Magento owners may need to change the default order number is because of compliance purposes. For example, a government agency or even your auditor may require a specific numbering format for order number for auditing purposes. Failure to change the numbers can lead to regulatory action and other problems.

  • Consistency
  • The second most common reason for changing the order number is consistency. You may be migrating from Magento 1 to Magento 2 and wish for the same order numbers to be carried forward. Secondly, you may be selling on multiple platforms and want that all platforms have the same order ID mechanism.

  • Reporting
  • Another possible reason for changing the default Magento 2 order number is the specific reporting or analytical requirements where specific order numbering formats make it easier to filter and analyse data.

  • Ease of Use
  • Lastly, you may consider changing the order numbering solely because you find it convenient. It may make order tracking easier for you or aligns with your personal preferences.

You might also consider reading: How to Cancel Order in Magento 2?

How to Change Order Number in Magento 2?

Here are some steps you can follow if you absolutely need to change order numbers in Magento 2:

Important Note: Before making any changes to your order numbers, it's important to back up your Magento database and test this procedure in a development or staging environment. Modifying order numbers in a live store can have unintended consequences. Check out our earlier article on ‘Magento 2 Modes: Set Developer, Production & Default Mode’ to change to development mode.

  1. Access the Database: Access your Magento 2 database using a database management tool (e.g., phpMyAdmin, MySQL Workbench).
  2. Locate the Sales Sequence Table: In the database, look for the table that stores order increment IDs. This table is sequence_order_1 .
  3. Update the Auto Increment ID: Click the 'Operations' tab and update the Auto_Increment column to your desired order number. For example, if you change the order number to 300007954, the next order numbers will be 300007955, 300007956, and so on.
  4. Update Other Related Tables: Orders are referenced in various other tables in the Magento database, including the sales_order and sales_order_grid tables. If you change order numbers, you may need to update references in these tables as well. This can be complex and may require custom SQL queries.
  5. Clear Cache and Reindex: After making changes to the database, clear the Magento cache and reindex data to ensure the changes take effect.

You can also do this by running the following SQL command.

ALTER TABLE sequence_order_1  AUTO_INCREMENT=300007954

How to Change Magento 2 Order Number Prefix?

If you wish to change the order number by adding a prefix or modifying an existing prefix, here’s what you need to do:

  1. Go to Database
  2. Add the following SQL commands:
    UPDATE ‘sales_sequence_profile’ SET ‘prefix’ = ‘X’ WHERE ‘meta_id’ = 5;
  3. The ‘X’ denotes the prefix. Change it to anything you wish to.

Conclusion:

That's all for changing the default order numbers in Magento 2. It's important that you follow best practices, test the changes in a development environment, and maintain proper documentation to make sure that your store's functionality is not compromised if you decide to proceed with changing order numbers. After making the changes, you need to clear the cache and reindex. If you run into an issue or have further queries, contact our team.

This blog was created with FME's SEO-friendly blog