WooCommerce Code Reference

Favorites

Contains logic for the WooCommerce Navigation menu.

Table of Contents

META_NAME  = 'navigation_favorites'
Array index of menu capability.
$instance  : Favorites|null
Favorites instance.
add_item()  : WP_Error|bool
Add item to favorites
get_all()  : WP_Error|array<string|int, mixed>
Get all registered favorites.
instance()  : mixed
Get class instance.
remove_item()  : WP_Error|bool
Remove item from favorites
set_meta_value()  : mixed
Set given favorites string to the user meta data.

Constants

Properties

Methods

add_item()

Add item to favorites

public static add_item(string $item_id, string|number $user_id) : WP_Error|bool
Parameters
$item_id : string

Identifier of item to add.

$user_id : string|number

Identifier of user to add to.

Return values
WP_Error|boolThrows exception if item already exists.

get_all()

Get all registered favorites.

public static get_all(string|number $user_id) : WP_Error|array<string|int, mixed>
Parameters
$user_id : string|number

Identifier of user to query.

Return values
WP_Error|array<string|int, mixed>

remove_item()

Remove item from favorites

public static remove_item(string $item_id, string|number $user_id) : WP_Error|bool
Parameters
$item_id : string

Identifier of item to remove.

$user_id : string|number

Identifier of user to remove from.

Return values
WP_Error|boolThrows exception if item does not exist.

set_meta_value()

Set given favorites string to the user meta data.

private static set_meta_value(string|number $user_id, array<string|int, mixed> $favorites) : mixed
Parameters
$user_id : string|number

User id.

$favorites : array<string|int, mixed>

Array of favorite values to set.

Return values
mixed