Blog | Technical

How to Delete an Order in Magento?


There are a few reasons why you might need to cancel an order in Magento; removing a test order, for example, or cancelling an order placed by mistake for a customer.

Whatever your reason, you need to know how to do it, and how to do it right.

In the oldest versions of Magento, it was not possible to delete the order completely. It was only possible to set order status to “cancelled”.

This was implemented by Magento to curb fraudulent actions, but it does make it frustrating for both developers and eCommerce website owners. When new sites are launched, they are often populated solely with test orders, which can make seeing new, real orders difficult.

(Plus, it looks messy and we hate messy!)

So, as a workaround, it became possible to delete orders by executing this MySQL query detailed below:

Select @order_id:=entity_id from sales_order_entity where increment_id='100000001';
Delete from sales_order_entity where [email protected]_id or [email protected]_id;

Following these queries, first you select the order ID from the sales table, and then you delete it using the second query.

This method can also be used by executing the MySQL query in the phpMyAdmin interface.

To do this, simply open your Magento database and click on the SQL tab. Then put in the required SQL query and execute it.

For the newer versions of Magento, there was another way to delete your test orders; PHP.

This PHP script will find the defined order, or orders, and delete them from the list:

$incrementId = 100000001;
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
$invoices = $order->getInvoiceCollection();
foreach ($invoices as $invoice){

$creditnotes = $order->getCreditmemosCollection();
foreach ($creditnotes as $creditnote){

$shipments = $order->getShipmentsCollection();
foreach ($shipments as $shipment){

All you have to do next is define the increment ID which will be used to search for the orders.

Usually, this ID contains only numbers like “100000037”.

Then, by using Magento functions, it will go through all the orders and find the one that matches the increment ID.

If you are looking for a completely built-in feature for deleting the orders, there is an extension you can install which will let you do this.

The extension can be found by visiting Magento Connect website and clicking Install Now.

It is worth noting that, in order to get this extension installed, you will first need to be logged into the Magento Connect website.

After installing the extension, simply open up the orders list in your Magento admin back end and select the order that you want to delete.

Click Delete Order from the Actions list and then click the Submit button.

You’ll find the order has been deleted successfully!

Know of any other methods that can delete orders from Magento? Let us know in the comments below!