How to Delete Orders in Magento
Magento, by default, does not let admin delete the orders entirely from the backend. They can be marked as canceled but can’t be deleted. If your store is loaded with test orders or any undesired orders, you may want to delete it, for which certain modifications are to be done in the database.
Refer the below methods and you’d be done with all the unwanted orders in your Magento store!
Methods to Delete Orders in Magento
- Delete one order at a time
Log in to PhpMyAdmin. Run the below-given commands:
1234set @increment_id='200000111';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; - Delete all orders at once
This step will delete all the orders irrespective of categories. So it is advisable to have a backup prior to implementing it.- Login to PhpMyAdmin.
- Run the following SQL commands:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586SET 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;-- lets reset customersTRUNCATE `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;-- Now, lets Reset all ID countersTRUNCATE `eav_entity_store`;ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;SET FOREIGN_KEY_CHECKS=1; - Delete orders using the script
You can delete the specified orders using a file with the same level as index.php. Replace the order_id of the orders you want to delete in the below script.
12345678910111213141516171819<?php$order = Mage::getModel('sales/order')->load($orderId);$invoices = $order->getInvoiceCollection();foreach ($invoices as $invoice) {$invoice->delete();}$creditnotes = $order->getCreditmemosCollection();foreach ($creditnotes as $creditnote) {$creditnote->delete();}$shipments = $order->getShipmentsCollection();foreach ($shipments as $shipment) {$shipment->delete();}$order->delete();?>
That’s it!
Any of the above-mentioned methods will help you delete orders in Magento store.
If you face any difficulty in the process, you may mention your doubts in the comments section below and I’d be happy to help.
Please share the post with Magento community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Sort Magento 2 Category Products by Stock Quantity
How to Create Popup in Magento 2
Next