wc_delete_order_item

Delete an item from the order it belongs to based on item id.

Description

wc_delete_order_item( (int) $item_id ); 

Parameters (1)

0. $item_id (int)
The item id.

Usage

  1. if ( !function_exists( 'wc_delete_order_item' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-item-functions.php'; 
  3.  
  4. // The item id. 
  5. $item_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_delete_order_item($item_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-item-functions.php  
  1. function wc_delete_order_item( $item_id ) { 
  2.  
  3. if ( ! $item_id = absint( $item_id ) ) { 
  4. return false; 
  5.  
  6. $data_store = WC_Data_Store::load( 'order-item' ); 
  7.  
  8. do_action( 'woocommerce_before_delete_order_item', $item_id ); 
  9.  
  10. $data_store->delete_order_item( $item_id ); 
  11.  
  12. do_action( 'woocommerce_delete_order_item', $item_id ); 
  13.  
  14. return true;