Automattic\WooCommerce\StoreApi\Routes\V1
ShopperListItemsByKey::get_route_delete_response
Delete a single item from a list.
Метод класса: ShopperListItemsByKey{}
Хуков нет.
Возвращает
\WP_REST_Response.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_route_delete_response( $request );
- $request(WP_REST_Request) (обязательный)
- Request object.
Код ShopperListItemsByKey::get_route_delete_response() ShopperListItemsByKey::get route delete response 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 );
}