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.
Метод класса: WC_REST_Orders_Controller{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->remove_item( $order, $item_type, $item_id ): void;
- $order(WC_Order) (обязательный)
- The order to remove the item from.
- $item_type(строка) (обязательный)
- The item type (from the request, not from the item, e.g.
'line_items'rather than 'line_item'). - $item_id(int) (обязательный)
- The ID of the item to remove.
Код WC_REST_Orders_Controller::remove_item() WC REST Orders Controller::remove item WC 10.9.4
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 );
}