{"id":147,"date":"2018-08-08T05:03:10","date_gmt":"2018-08-08T05:03:10","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/08\/08\/delete-orders-in-magento\/"},"modified":"2025-05-22T17:24:30","modified_gmt":"2025-05-22T11:54:30","slug":"delete-orders-in-magento","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/delete-orders-in-magento\/","title":{"rendered":"How to Delete Orders in Magento"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento, by default, does not let admin delete the orders entirely from the backend. They can be marked as canceled but can\u2019t 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Refer the below methods and you\u2019d be done with all the unwanted orders in your Magento store!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to Delete Orders in Magento<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1: Delete one order at a time<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Log in to<strong>&nbsp;PhpMyAdmin<\/strong>. Run the below-given commands:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">set @increment_id='200000111';\nselect @order_id:=entity_id from prefix_sales_order_entity where increment_id=@increment_id;\ndelete from prefix_sales_order_entity where entity_id=@order_id or parent_id=@order_id;\ndelete from prefix_sales_order where increment_id=@increment_id;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The order_id is to be replaced with the ID of the order to be deleted. Set the prefix that is selected in the Magento store.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method 2: Delete all orders at once<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This step will delete all the orders irrespective of categories. So it is advisable to have a backup prior to implementing it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Login to&nbsp;<strong>PhpMyAdmin<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following SQL query:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SET FOREIGN_KEY_CHECKS=0;\nTRUNCATE `sales_order`;\nTRUNCATE `sales_order_datetime`;\nTRUNCATE `sales_order_decimal`;\nTRUNCATE `sales_order_entity`;\nTRUNCATE `sales_order_entity_datetime`;\nTRUNCATE `sales_order_entity_decimal`;\nTRUNCATE `sales_order_entity_int`;\nTRUNCATE `sales_order_entity_text`;\nTRUNCATE `sales_order_entity_varchar`;\nTRUNCATE `sales_order_int`;\nTRUNCATE `sales_order_text`;\nTRUNCATE `sales_order_varchar`;\nTRUNCATE `sales_flat_quote`;\nTRUNCATE `sales_flat_quote_address`;\nTRUNCATE `sales_flat_quote_address_item`;\nTRUNCATE `sales_flat_quote_item`;\nTRUNCATE `sales_flat_quote_item_option`;\nTRUNCATE `sales_flat_order_item`;\nTRUNCATE `sendfriend_log`;\nTRUNCATE `tag`;\nTRUNCATE `tag_relation`;\nTRUNCATE `tag_summary`;\nTRUNCATE `wishlist`;\nTRUNCATE `log_quote`;\nTRUNCATE `report_event`;\nALTER TABLE `sales_order` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_int` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_text` AUTO_INCREMENT=1;\nALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;\nALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;\nALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;\nALTER TABLE `tag` AUTO_INCREMENT=1;\nALTER TABLE `tag_relation` AUTO_INCREMENT=1;\nALTER TABLE `tag_summary` AUTO_INCREMENT=1;\nALTER TABLE `wishlist` AUTO_INCREMENT=1;\nALTER TABLE `log_quote` AUTO_INCREMENT=1;\nALTER TABLE `report_event` AUTO_INCREMENT=1;\n-- lets reset customers\nTRUNCATE `customer_address_entity`;\nTRUNCATE `customer_address_entity_datetime`;\nTRUNCATE `customer_address_entity_decimal`;\nTRUNCATE `customer_address_entity_int`;\nTRUNCATE `customer_address_entity_text`;\nTRUNCATE `customer_address_entity_varchar`;\nTRUNCATE `customer_entity`;\nTRUNCATE `customer_entity_datetime`;\nTRUNCATE `customer_entity_decimal`;\nTRUNCATE `customer_entity_int`;\nTRUNCATE `customer_entity_text`;\nTRUNCATE `customer_entity_varchar`;\nTRUNCATE `log_customer`;\nTRUNCATE `log_visitor`;\nTRUNCATE `log_visitor_info`;\nALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;\nALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;\nALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;\nALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;\nALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;\nALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;\nALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;\nALTER TABLE `log_customer` AUTO_INCREMENT=1;\nALTER TABLE `log_visitor` AUTO_INCREMENT=1;\nALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;\n-- Now, lets Reset all ID counters\nTRUNCATE `eav_entity_store`;\nALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;\nSET FOREIGN_KEY_CHECKS=1;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Method 3: Delete orders using the script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can delete the specified orders using a file with the same level as&nbsp;<strong>index.php.&nbsp;<\/strong>Replace the order_id of the orders you want to delete in the below script.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n$order = Mage::getModel('sales\/order')->load($orderId);\n$invoices = $order->getInvoiceCollection();\nforeach ($invoices as $invoice) {\n    $invoice->delete();\n}\n \n$creditnotes = $order->getCreditmemosCollection();\nforeach ($creditnotes as $creditnote) {\n    $creditnote->delete();\n}\n \n$shipments = $order->getShipmentsCollection();\nforeach ($shipments as $shipment) {\n    $shipment->delete();\n}\n \n$order->delete();\n?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Any of the above methods will help you delete orders in the Magento store.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento, by default, does not let admin delete the orders entirely from the backend. They can be marked as canceled but can\u2019t be deleted. If&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":15626,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/147\/revisions\/15626"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}