Table of Contents
Proper order management is key to running a successful online store. However, Magento 2 does not let you delete orders directly. In order management, one can only Cancel, Hold, or Unhold orders, but there is no such option to remove Magento orders from the database completely. This can make organizing your backend challenging. Deleting unnecessary orders, like test transactions or duplicates, helps keep your order grid clean and ensures accurate data management. This is especially useful before launching your store to avoid clutter and confusion.
When you delete an order in Magento 2, all related documents like invoices, shipments, and credit memos are removed as well. Thus, deleting orders is permanent, so be cautious. Make sure to save any important sales data for reporting or auditing.
How to Delete Orders in Magento 2
Use a 3rd Party Module
Since Magento 2 doesn’t offer a built-in option to delete orders, you’ll need to use a third-party extension. Nowadays, there are many free Magento 2 extensions that add the possibility to delete orders in Magento 2. Simply install the extension, and the delete option will become available in the Order Management section.
One such free extension is M2 Delete orders module from SwissUpLabs. The module offers a simple and secure way to remove Magento orders, shipments, credit memos, and invoices. With the SwissUpLabs M2 Delete Orders extension, you can delete a single order or multiple orders with just one click. This helps keep your Admin panel clean and organized.
This module is ideal for:
- Magento 2 websites preparing for launch;
- Stores creating multiple test orders;
- Removing outdated orders you no longer need.
Delete Orders Manually in Magento 2
You can remove Magento orders manually by following these steps:
Step 1: Access PhpMyAdmin
Log in to your database management system (like PhpMyAdmin) to execute the necessary commands.
Step 2: Delete a Single Order
Use the following command to delete one specific order. Replace 100000011 with the ID of the order you want to delete, and update the prefix to match your store’s database prefix:
SQL
SET @increment_id='100000011';
SELECT @order_id:=entity_id FROM prefix_sales_order_entity WHERE increment_id=@increment_id;
DELETE FROM prefix_sales_order_entity WHERE entity_id=@order_id OR parent_id=@order_id;
DELETE FROM prefix_sales_order WHERE increment_id=@increment_id;
Step 3: Delete All Orders at Once
To delete all orders in bulk, run these commands. Please note that these will remove all orders, invoices, shipments, and related data:
SQL
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_grid`;— Add other tables as needed, such as `sales_invoice`, `sales_creditmemo`, etc.
SET FOREIGN_KEY_CHECKS=1;Step 4: Reset Auto-Increment Values
After deleting orders, reset the auto-increment values for the affected tables to start fresh:
SQL
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;— Add similar commands for other truncated tables.
Step 5: Delete Customer-Related Data (Optional)
To clear customer information, use these commands:
SQL
TRUNCATE `customer_entity`;
TRUNCATE `customer_address_entity`;— Add similar commands for related tables like `log_customer`, `log_visitor`, etc.
Step 6: Clean Order History and Related Data (Optional)
You can clean order history and other related information with these commands:
SQL
TRUNCATE `sales_order`;
TRUNCATE `sales_order_grid`;
TRUNCATE `sales_invoice`;
TRUNCATE `sales_shipment`;— Add other related tables as needed.
Important Notes:
- Be very careful when running these commands, as they delete data permanently.
- Always back up your database before performing any deletions.
- Make sure to disable FOREIGN_KEY_CHECKS where necessary and re-enable it after completing the deletions.
Thus, by following these steps, you can manually delete unwanted orders and related data in Magento 2.
Benefits of Using Magento 2 Delete Orders Extensions
Magento 2 Delete orders extensions are helpful tools for managing your store when Magento’s default features fall short. They allow:
- Improved Order Management
These extensions enhance the order grid by adding advanced filtering options. You can easily delete single or multiple orders directly from the grid, keeping everything organized. - Easy Bulk Order Handling
Extensions are especially useful for managing bulk orders or testing scenarios. Using a separate test server allows you to experiment safely without affecting your live store. We recommend having a strong Magento test server setup for such purposes. - Efficient Backend Operations
While customer experience is crucial on the frontend, a smooth and efficient backend also plays a big role in overall satisfaction. A clean and organized admin panel makes managing your store easier and improves workflows.
Conclusion
Managing orders accurately is essential for the success and smooth operation of an online store. However, Magento 2 does not have a built-in option to delete orders, which can be a challenge for store owners. To solve this, one needs to manually delete orders, which can be time-consuming, or use third-party extensions, which is faster and more beneficial.