How to add programmatically new order status and state using Data Patch in Magento 2?

To create new order status and state follow below steps:

  1. Create folder Setup/Patch/Data in your module
  2. Create file UpdateOrderStatuses.php
  3. Implement method apply in the class UpdateOrderStatuses
  4. Run bin/magento setup:upgrade

When you run Upgrade command, Magento runs your patch and it will add your patch path to the patch_list table.

MM/Training/Setup/Patch/Data/UpdateOrderStatuses.php

Here MM_Training my module and below code you have to add into UpdateOrderStatuses.php

Leave a Reply

Your email address will not be published. Required fields are marked *