WC_REST_Orders_Controller::remove_item
Wrapper method to remove order items. When updating, the item ID provided is checked to ensure it is associated with the order.
Method of the class: WC_REST_Orders_Controller{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->remove_item( $order, $item_type, $item_id ): void;
- $order(WC_Order) (required)
- The order to remove the item from.
- $item_type(string) (required)
- The item type (from the request, not from the item, e.g. 'line_items' rather than 'line_item').
- $item_id(int) (required)
- The ID of the item to remove.
WC_REST_Orders_Controller::remove_item() WC REST Orders Controller::remove item code WC 10.4.3
protected function remove_item( WC_Order $order, string $item_type, int $item_id ): void {
$item = $order->get_item( $item_id );
if ( ! $item ) {
throw new WC_REST_Exception(
'woocommerce_rest_invalid_item_id',
esc_html__( 'Order item ID provided is not associated with order.', 'woocommerce' ),
400
);
}
if ( 'line_items' === $item_type ) {
require_once WC_ABSPATH . 'includes/admin/wc-admin-functions.php';
wc_maybe_adjust_line_item_product_stock( $item, 0 );
}
/**
* Allow extensions be notified before the item is removed.
*
* @param WC_Order_Item $item The item object.
*
* @since 9.3.0.
*/
do_action( 'woocommerce_rest_remove_order_item', $item );
$order->remove_item( $item_id );
}