Delete all commerce products

The commerce_product_delete_multiple function can be used to bulk delete products. 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);
  
  $product_ids = db_select('commerce_product', 'p')
  ->fields('p', array('product_id'))
  ->execute()->fetchCol();
  
//   $products = commerce_product_load_multiple($product_ids);
  commerce_product_delete_multiple($product_ids);

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

Products can't be deleted when there are references in orders. First of all, delete all orders.

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.