Automattic\WooCommerce\StoreApi\Routes\V1

ShopperListItemsByKey::get_route_delete_responseprotectedWC 1.0

Delete a single item from a list.

Method of the class: ShopperListItemsByKey{}

No Hooks.

Returns

\WP_REST_Response.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_route_delete_response( $request );
$request(WP_REST_Request) (required)
Request object.

ShopperListItemsByKey::get_route_delete_response() code WC 10.9.1

protected function get_route_delete_response( \WP_REST_Request $request ) {
	$list = ShopperList::get_by_slug( (string) $request['slug'] );

	if ( ! $list ) {
		throw new RouteException( 'woocommerce_rest_shopper_list_not_found', esc_html__( 'Your saved list isn\'t available right now.', 'woocommerce' ), 404 );
	}

	if ( ! $list->remove_item( (string) $request['key'] ) ) {
		throw new RouteException( 'woocommerce_rest_shopper_list_item_not_found', esc_html__( 'That item isn\'t in your saved list anymore.', 'woocommerce' ), 404 );
	}

	$list->save();

	return new \WP_REST_Response( null, 204 );
}