Automattic\WooCommerce\Admin\Features\Navigation

Favorites::remove_item()public staticWC 1.0

Remove item from favorites

Method of the class: Favorites{}

No Hooks.

Return

\WP_Error|Boolean. Throws exception if item does not exist.

Usage

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

Favorites::remove_item() code WC 9.0.1

public static function remove_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_does_not_exist',
			__( 'Favorite item not found', 'woocommerce' )
		);
	}

	$remaining = array_values( array_diff( $all_favorites, [ $item_id ] ) );

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

	return true;
}