Abstract_WC_Order_Data_Store_CPT::delete_items()publicWC 1.0

Remove all line items (products, coupons, shipping, taxes) from the order.

Method of the class: Abstract_WC_Order_Data_Store_CPT{}

No Hooks.

Return

null. Nothing (null).

Usage

$Abstract_WC_Order_Data_Store_CPT = new Abstract_WC_Order_Data_Store_CPT();
$Abstract_WC_Order_Data_Store_CPT->delete_items( $order, $type );
$order(WC_Order) (required)
Order object.
$type(string)
Order item type.
Default: null

Abstract_WC_Order_Data_Store_CPT::delete_items() code WC 9.4.2

public function delete_items( $order, $type = null ) {
	global $wpdb;

	if ( ! empty( $type ) ) {
		$wpdb->query( $wpdb->prepare( "DELETE itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta as itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items as items WHERE itemmeta.order_item_id = items.order_item_id AND items.order_id = %d AND items.order_item_type = %s", $order->get_id(), $type ) );
		$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = %s", $order->get_id(), $type ) );
	} else {
		$wpdb->query( $wpdb->prepare( "DELETE itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta as itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items as items WHERE itemmeta.order_item_id = items.order_item_id and items.order_id = %d", $order->get_id() ) );
		$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d", $order->get_id() ) );
	}

	$this->clear_caches( $order );
}