Automattic\WooCommerce\Internal\ShopperLists
ShopperList::get_by_slug
Load a list by slug. Returns false for any other list that doesn't exist.
Method of the class: ShopperList{}
No Hooks.
Returns
self|false.
Usage
$result = ShopperList::get_by_slug( $slug, ?int $user_id );
- $slug(string) (required)
- List identifier.
- ?int $user_id
- .
Default:null
ShopperList::get_by_slug() ShopperList::get by slug code WC 10.9.1
public static function get_by_slug( string $slug, ?int $user_id = null ) {
// Gate disabled or unknown slugs upfront so previously-persisted lists
// don't bypass the feature flag (the Store API surfaces this as 404).
if ( ! wc_get_container()->get( ShopperListsController::class )->is_enabled( $slug ) ) {
return false;
}
$user_id = absint( $user_id ? $user_id : get_current_user_id() );
if ( ! $user_id ) {
return false;
}
$stored = Users::get_site_user_meta( $user_id, self::META_KEY_PREFIX . $slug );
if ( is_array( $stored ) ) {
return self::from_array( $stored, $user_id );
}
// In-memory list; saved on the first save().
return new self(
$user_id,
$slug,
current_time( 'mysql', true ),
array()
);
}