Automattic\WooCommerce\Admin\Features\Navigation

Favorites::add_item()public staticWC 1.0

Add item to favorites

{} It's a method of the class: Favorites{}

No Hooks.

Return

WP_Error|Boolean. Throws exception if item already exists.

Usage

$result = Favorites::add_item( $item_id, $user_id );
$item_id(string) (required)
Identifier of item to add.
$user_id(string|number) (required)
Identifier of user to add to.

Code of Favorites::add_item() WC 7.1.0

public static function add_item( $item_id, $user_id ) {

	$all_favorites = self::get_all( $user_id );

	if ( in_array( $item_id, $all_favorites, true ) ) {
		return new \WP_Error(
			'woocommerce_favorites_already_exists',
			__( 'Favorite already exists', 'woocommerce' )
		);
	}

	$all_favorites[] = $item_id;

	self::set_meta_value( $user_id, $all_favorites );

	return true;
}