Automattic\WooCommerce\Admin\API
NavigationFavorites::add_item()
Add a favorite.
Метод класса: NavigationFavorites{}
Хуков нет.
Возвращает
WP_REST_Response
.
Использование
$NavigationFavorites = new NavigationFavorites(); $NavigationFavorites->add_item( $request );
- $request(WP_REST_Request) (обязательный)
- Request data.
Код NavigationFavorites::add_item() NavigationFavorites::add item WC 9.3.3
public function add_item( $request ) { $user_id = get_current_user_id(); $fav_id = $request->get_param( 'item_id' ); $user = get_userdata( $user_id ); if ( false === $user ) { return $this->prepare_error( new \WP_Error( 'woocommerce_favorites_invalid_user', __( 'Invalid user_id provided', 'woocommerce' ) ) ); } $response = Favorites::add_item( $fav_id, $user_id ); if ( is_wp_error( $response ) || ! $response ) { return rest_ensure_response( $this->prepare_error( $response ) ); } return rest_ensure_response( Favorites::get_all( $user_id ) ); }