WC_Order_Item_Data_Store::delete_order_item()publicWC 3.0.0

Delete an order item.

Method of the class: WC_Order_Item_Data_Store{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Order_Item_Data_Store = new WC_Order_Item_Data_Store();
$WC_Order_Item_Data_Store->delete_order_item( $item_id );
$item_id(int) (required)
Item ID.

Changelog

Since 3.0.0 Introduced.

WC_Order_Item_Data_Store::delete_order_item() code WC 9.4.2

public function delete_order_item( $item_id ) {
	// Load the order ID before the deletion, since after, it won't exist in the database.
	$order_id = $this->get_order_id_by_order_item_id( $item_id );

	global $wpdb;
	$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d", $item_id ) );
	$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d", $item_id ) );

	$this->clear_caches( $item_id, $order_id );
}