0

I tried to delete my order list but could not delete those orders and searched on google. They provide the solutions with the use of an extension but I do not want to use extension. I would like to have a good way of doing it programatically.

1

Magento 2 focuses on use of API primarily for CRUD operation so you may proceed as follows: Inject OrderInterface in your class.

protected $order;
public function __construct(
    \Magento\Sales\Api\Data\OrderInterface $order,
    ......
) {
    $this->order = $order;

}

Load order object by increment id, and delete it.

Increment id and order id are completely different entities so do not confuse with them.

Create a method within your class as:

function deleteOrderByIncrementId($incrementId = null )
{
    if($incrementId){
        $this->order->loadByIncrementId($incrementId);
        $this->order->delete();
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.