How to change the default order increment ID in Magento 2?

Say, you want to change the Magento order increment ID in your Magento 2 store with a custom one. You can do this in 2 ways:

Let’s consider them both.

Method 1. Change increment ID programmatically

Warning: The code provided below is illustrative. You need to customize it for your specific Magento 2 installation.

Step 1. Register a new module by creating a file app/code/Amasty/Testgrid/registration.php


Step 2. Next, you need to create the module.xml file in the app/code/Amasty/Testgrid/etc folder to define installation and update functions.

<?xml version="1.0"?>
<config xmlns:xsi=""
<module name="Amasty_Testgrid" setup_version="1.0.0">

Step 3. Then, create app/code/Amasty/Testgrid/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi=""
<type name="Magento\Framework\DB\Sequence\SequenceInterface">
<argument name="pattern" xsi:type="string">ABC%s%'.06d%sDFG</argument>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source"
<type name="Amasty\Testgrid\Model\ResourceModel\Order\Grid\Collection">
<argument name="mainTable" xsi:type="string">sales_order_grid</argument>
<argument name="resourceModel"

And change the pattern from "%s%'.09d%s" to “ABC%s%'.06d%sDFG”. In this case, ABC is a Magento 2 order increment ID prefix, and DFG is postfix. They will change the Magento 2 default order number. Also, in our example, we reduced the number of digits from 9 to 6.

If you want to start order numeration from a specific digit, check the official documentation to see how to do it.

Method 2. Change increment ID via the Magento 2 Custom Order Number plugin

In Magento 2 to load order by increment ID, you can use extensions. The Custom Order Number extension allows you to get orders by increment id in Magento 2 and manage increment ID the way you want. You can add prefix, postfix, change the counter increment step and padding. It supports different variables like:

  • {store} for store name;
  • {yyyy} for a year;
  • {mm} for a month;
  • {dd} for a day;
  • {country_code} for a country code.

You can use them to specify number format. With this extension, you can change Order, Invoice, Shipping, and Credit Memo data. Moreover, you can set different counters for each website and store view. 

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.

© 2009-2024 Amasty. All Rights Reserved.