How to Delete Orders in Magento 2? Detailed Guide

How to Delete Orders in Magento 2? Detailed Guide

Precise order management is crucial for an online store's success and operational efficiency. However, the absence of a delete order Magento 2 feature is a problem for store owners. To fix the problem, store owners must rely on third-party extensions or undergo tedious manual deletion of orders.


In this post, we’ll discuss how you can configure a delete order extension in Magento 2. You’ll also find out how to delete orders manually using commands.

Key Takeaways

  • Understand the importance of deleting orders in Magento 2, including related documents like invoices, shipments, and credit memos.

  • Discover how to clear unwanted data, such as test orders, from the Magento order grid for a well-organized Magento admin panel.

  • Understand the options for deleting single or multiple orders in Magento 2, whether through extensions or manual methods.

Why is it important to delete orders in Magento 2?

Deleting orders in Magento 2 allows removing all order-related documents. It includes Magento invoices, shipments, and credit memos. It allows clearing unwanted data, like the test orders, from the Magento order grid and ensures organized admin backends. Organizing the order grid in the backend can also include rectifying incorrect orders, removing duplicate entries, and clearing test transactions.

Magento store owners might find it useful to delete test orders. It ensures data accuracy before a store goes live. However, deleting orders is permanent, and you should maintain caution while removing orders from the grid. Ensure the sales data is preserved for reporting and auditing purposes.

Order Deletion from Magento Admin Backend

By default, Magento does not allow an easy way to delete orders through the admin panel. You must install a Magento 2 extension to delete orders and related data. After integrating the delete orders extension on your Magento store, follow the steps below to configure it:

  1. Log in to your Magento 2 admin panel.

  2. Go to Stores. Then, click Configurations.

  3. On the side panel, scroll down and click the Extensions section.

  4. Click the Delete Order extension from the list of extensions integrated into your Magento store.

  5. Expand the General section.

  6. Set the Enable field to Yes.

  7. Click the Save Config button to make the changes permanent.

Magento 2 Admin Panel showing General Settings for Order Deletion Extension

After successfully configuring the ‘delete orders’ extension, you can use it to remove unwanted orders from the order grid hassle-free.

To delete orders from Magento 2, follow the below steps:

  1. Log in to your Magento 2 admin panel.

  2. Go to the Sales section and click Orders.

  3. Select the checkbox for the orders you wish to delete. Alternatively, you can use the Select All checkbox to delete all orders simultaneously.

  4. Under the Actions drop-down, select Delete.

  5. To confirm, click OK on the deletion notification.

Magento 2 Admin Backend Interface for Deleting Orders

Delete Orders in Magento Manually

To perform manual deletion of Magento orders. You can follow the below-mentioned steps:

  1. Access the PhpMyAdmin.

  2. Run the following command to delete a single order:

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;
  1. Replace the order_id in the above code with the ID of the order you wish to delete. Set the prefix you selected in the Magento store.

  2. Run the following command to delete all orders at once:

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
  1. To delete customer info:
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
  1. To clean the Magento order history:
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
  1. To clean Magento order-related information:
TRUNCATE TABLE `sales_creditmemo`;
TRUNCATE TABLE `sales_creditmemo_comment`;
TRUNCATE TABLE `sales_creditmemo_grid`;
TRUNCATE TABLE `sales_creditmemo_item`;
TRUNCATE TABLE `sales_invoice`;
TRUNCATE TABLE `sales_invoiced_aggregated`;
TRUNCATE TABLE `sales_invoiced_aggregated_order`;
TRUNCATE TABLE `sales_invoice_comment`;
TRUNCATE TABLE `sales_invoice_grid`;
TRUNCATE TABLE `sales_invoice_item`;
TRUNCATE TABLE `sales_order`;
TRUNCATE TABLE `sales_order_address`;
TRUNCATE TABLE `sales_order_aggregated_created`;
TRUNCATE TABLE `sales_order_aggregated_updated`;
TRUNCATE TABLE `sales_order_grid`;
TRUNCATE TABLE `sales_order_item`;
TRUNCATE TABLE `sales_order_payment`;
TRUNCATE TABLE `sales_order_status_history`;
TRUNCATE TABLE `sales_order_tax`;
TRUNCATE TABLE `sales_order_tax_item`;
TRUNCATE TABLE `sales_payment_transaction`;
TRUNCATE TABLE `sales_refunded_aggregated`;
TRUNCATE TABLE `sales_refunded_aggregated_order`;
TRUNCATE TABLE `sales_shipment`;
TRUNCATE TABLE `sales_shipment_comment`;
TRUNCATE TABLE `sales_shipment_grid`;
TRUNCATE TABLE `sales_shipment_item`;
TRUNCATE TABLE `sales_shipment_track`;
TRUNCATE TABLE `sales_shipping_aggregated`;
TRUNCATE TABLE `sales_shipping_aggregated_order`;

Benefits of Using Magento 2 Delete Order Extensions

Specialized extensions are useful when Magento lacks easy solutions for managing online stores.

1. Better Order Grid

Magento extensions enhance the default order grid, giving you advanced filtering options. They also provide the ability to delete single or multiple orders directly from the grid view.

2. Handling Bulk Orders

Handy extensions are useful when dealing with bulk orders or setting up scenarios for testing purposes. Also, using a separate test server allows you to experiment and tweak settings without any risk to your live store. MGT-Commerce recommends having a robust Magento test server configuration for this very purpose.

3. Balancing User Experience with Backend Efficiency

While user experience is paramount in a store’s frontend, backend efficiency significantly impacts overall customer satisfaction. A well-designed backend simplifies administrative tasks and looks eye-pleasing on the customer interface.

Best Practices for Deleting Test Orders in Magento 2

Here are some guidelines for managing test orders:

  1. Always perform deletions on a Magento test server to prevent affecting your live data.

  2. Backup your database regularly, especially before performing bulk deletions.

  3. Use extensions that allow deletion without hindering other order’s data.

FAQs

1. How can I delete a Magento 2 order with related data like invoices, shipments, and credit memos?

In Magento 2, you can delete an order, including its related data, such as invoices, shipments, and credit memos, using an order management extension. You can also perform manual deletion via the command line.


2. Can I delete all orders in my Magento 2 online store simultaneously?

Yes. Store admins can delete multiple orders or cancel orders in your Magento 2 online store by integrating and configuring an extension that allows you to remove unnecessary orders from the Magento database.


3. Is it possible to delete just one order in Magento 2 without affecting other orders?

Magento 2 extensions allow you to delete one order without impacting other orders in your store.


4. Does Magento 2 have a feature to delete all test orders quickly?

Magento 2 doesn’t offer an in-built solution to delete all test orders swiftly. However, you can use Magento extensions to remove junk orders from your open-source online store.

Summary

The feature to delete order Magento 2 ensures a clutter-free backend order grid for store admins. Following the steps mentioned in this tutorial, you can configure and use an extension to delete orders and related data in your Magento store. Want to enhance the efficiency of your eCommerce business further? Consider implementing a managed Magento hosting to streamline your online store’s optimization process.

Vaishali S.
Vaishali S.
Technical Writer

As a seasoned writer, Vaishali consistently expands her knowledge in Magento hosting. She has four years of professional experience, with a focus on crafting diverse Magento-related content.


Get the fastest Magento Hosting! Get Started