Home » Tutorials For Beginner » How to programmatically delete order in Magento

How to programmatically delete order in Magento

Have you questioned yourself how to delete test order created in Magento? You got a Magento project, you placed some test orders to see if Shipping and Payment methods work as expected. Everything seems to be cool and the client wishes to launch the site. You launch it. When you enter the administration for the first time after the launch, you will see all your test orders there. You know those orders should be removed. But how?

If you try to delete orders in the backend, you will find out that you can only set the status to “cancelled” and the order is still there.  Unfortunately, Magento doesn’t enable us to delete those via administration, so you will not see any “Delete order” button. This can be quite frustrating both to developers and the merchants.

In this article we will go through how to delete a single order and all orders

How To Delete A Single Order Using PhpMyAdmin

You need to run the following query on your database using PhpMyAdmin:

In the above example we are trying to delete test order # ’200000111′. Generally people use prefix so change the “prefix_” in the above query with the prefix you have chosen for your Magento store.

The above query will delete the single test order or even an actual order from your Magento store. All you have to do is provide an order number and database prefix. Rest will be taken care of automatically.

Delete All Magento Orders at once

This step is done only on new store which are ready forproduction and don’t have any “Actual Orders” in the system. I would highly recommend taking a full backup before you proceed. Basically when you run the following queries on your Magento database it will complete wipe out all the records and reset the order counters. If you are about to indulge, then please make sure that you know what you are doing.

Beware: The following steps can’t be reversed.

Method 1: Create php script in Magento root folder, copy this code into script and run script.

Method 2: Go to your PhpMyAdmin and run SQL Query

Optional: If you are looking to set appropriate prefixes for orders, invoices, shipments, credit memos then run the following query as well:

Now, all the orders, customer orders, logs etc are all gone from your Magento store and it will be in a clean state to start over.

Should you run into any trouble? feel free drop a comment and let me know.

About Brian Wilson

Brian is a freelance Magento developer with 5 years of experience with customizing Magento extensions, magento themes. He's interested in sharing Magento Tutorials to the community

One comment

  1. avatar

    Thanks for the guide, it’s working like a charm. Deleting order in back-end doesn’t completely remove orders but this did the trick.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top