add order status

Today we are going to demonstrate how to add list of order statuses in system configuration in Magento 2. This can be useful when you don’t want to hard code order status in the code especially when you are adding multiple order status.

Add source model “MagentoSalesModelConfigSourceOrderStatus” to get the list of order statuses.

The below code will show you the multi select box where you can select more than one order statuses

<field id="order_status_planned_to_ship" translate="label" type="multiselect" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Order Statuses</label> <source_model>MagentoSalesModelConfigSourceOrderStatus</source_model>
</field>

The below code will show you the select box where you can select one order status

<field id="order_status_planned_to_ship" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Order Statuses</label> <source_model>MagentoSalesModelConfigSourceOrderStatus</source_model>
</field>

That’s it, Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

Similar Posts