Automattic\WooCommerce\StoreApi\Routes\V1
CartRemoveItem::get_route_post_response
Handle the request and return a valid response for this endpoint.
Method of the class: CartRemoveItem{}
Hooks from the method
Returns
\WP_REST_Response.
Usage
// protected - for code of main (parent) or child class $result = $this->get_route_post_response( $request );
- $request(WP_REST_Request) (required)
- Request object.
CartRemoveItem::get_route_post_response() CartRemoveItem::get route post response code WC 10.7.0
protected function get_route_post_response( \WP_REST_Request $request ) {
$cart = $this->cart_controller->get_cart_instance();
$cart_item = $this->cart_controller->get_cart_item( $request['key'] );
if ( empty( $cart_item ) ) {
throw new RouteException( 'woocommerce_rest_cart_invalid_key', __( 'Cart item no longer exists or is invalid.', 'woocommerce' ), 409 );
}
$removed = $cart->remove_cart_item( $request['key'] );
if ( $removed ) {
/**
* Fires when a cart item is removed from a user request.
*
* @param string $cart_item_key Cart item key.
* @param \WC_Cart $cart Cart object.
*
* @since 10.6.0
*/
do_action( 'internal_woocommerce_cart_item_removed_from_user_request', $request['key'], $cart );
}
$this->maybe_release_stock();
return rest_ensure_response( $this->schema->get_item_response( $cart ) );
}