Complete Tutorial Guide to Change Order Number in Magento 2

Because of the limitation of order number in default Magento 2, many merchants are finding a solution to make modifications to order number. In fact, you are totally able to customize it. In this article, we’ll provide you some tips to change the default Magento 2 order number in the correct way, they are:

  • Manually make changes directly in database: use code and commands to edit order increment ID, order number start and prefix
  • Install an extension

Tip 1: Make Changes to Order Number Directly in Database Magento 2

First of all, you need to open your PHP Admin database. Then find and open the table “sale_sequence_profile”.

This is the structure of table “sale_sequence_profile”:

magento-2-custom-order-number “sale_sequence_profile” table

After that, you can make changes to default order number in your Magento 2 website:

a. Change Order Increment ID

This is the guide to help you change the step between 2 continuous order numbers.

Step 1:  Open Database and add the following SQL commands:

UPDATE ‘sales_sequence_profile’ SET ‘step’ = X  WHERE ‘meta_id’ = 5;

 

Note: “meta_id” is gotten from table “sales_sequence_meta”

magento-2-custom-order-number "sales_sequence_meta" table

Step 2: Replace ‘X by the order you wish to make

Step 3: Run the query

b. Change Order Number Prefix

Following this structure to add the prefix to the order number:

Step 1:  Go to Database and add the following SQL commands:

UPDATE ‘sales_sequence_profile’ SET ‘prefix’ = ‘XWHERE ‘meta_id’ = 5;

 

Step 2: replace “X” with the order prefix you want.

Note: If you wish to disable prefix, remove the quotes and set x=NULL

Step 3: Run the query

c. Change Order Number Suffix

Step 1:  Go to Database and add the following SQL commands:

UPDATE ‘sales_sequence_profile’ SET ‘suffix’= ‘XWHERE ‘meta_id’ = 5;

Step 2: replace “X” with the order prefix you want.

Note: If you wish to disable suffix, remove the quotes and set X=NULL

Step 3: Run the query

d. Change Order Number Start-value

Step 1:  Go to Database and add the following SQL commands:

UPDATE ‘sales_sequence_profile’ SET ‘start_value’= X WHERE ‘meta_id’ = 5;

Step 2: replace “X” with the number you wish to make.

Step 3: Run the query

e. Change Pad-length

The constant DEFAULT_PATTERN is set in: /vendor/magento/module-sales-sequence/Model/Sequence.php, line 22.

magento-2-custom-order-number Default path-lenghth

To avoid editing module core, you can change this in a custom module by creating etc/di.xml with the following contents:

magento-2-custom-order-number Creating etc/di.xml

After setting, you will get a new custom order number like this:

order_number = prefix + ((sequence_value – start_value) * step + start_value) {padded to X digits} + suffix

For example, you set: - step = ‘10’’ - prefix = ‘Bss-’ - suffix = ‘-M2’ - start_value = ‘1’ - DEFAULT_PATTERN = "%s%'.03d%s"

And last sequence_value = 2 => next sequence_value = 3

Then next order number is Bss-021-M2

Note: sequence_value is gotten from table “sequence_order_1”

Tip 2: Use Magento 2 Custom Order Number extension

The damage of using code is that it directly intervenes in the database, which may cause harm to your website especially for those who do not get familiar with it. Hence, another tip to change order number simply safely is to use the support of a convenient extension. You can refer Magento 2 Custom Order Number extension. The extension is very user-friendly so admins can make changes to order number at ease. This module not only allows you to make a change to order number but also shipment, credit memo, and invoice number. One plus point is that you can edit the sale numberings individually for each store view.

magento-2-custom-order-number-extension Magento 2 Custom Order Number extension configuration

Conclusion

In conclusion, you can completely customize order numbers by making changes right in the database or use Magento 2 Custom Order Number extension. Personally, I highly recommend you to use the second choice as it does not directly interfere with the database. Hope it helps!

magento-2-custom-order-number-extension

One thought on “Complete Tutorial Guide to Change Order Number in Magento 2”

Leave a Reply