Delete all commerce orders

The commerce_order_delete_multiple function can be used to bulk delete orders. Similar to other ENTITY_delete_multiple functions, an array of entity ids is passed as an argument.
Drupal_set_time_limit is used to override the default 30 seconds that a script is allowed to run.


  drupal_set_time_limit(0);
  
  $order_ids = db_select('commerce_order', 'o')
  ->fields('o', array('order_id'))
  ->execute()->fetchCol();
  
  //   $orders = commerce_order_load_multiple($order_ids);
  commerce_order_delete_multiple($order_ids);

This code can be placed in a custom module as a menu callback or can be triggered on a form submit.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.