Useful Functions
Addonify Wishlist has defined some useful helper functions that you may want to use. The helper functions could be found inside inc/addonify-wishlist-helper-functions.php file.
Some of the helper functions are as follows:
// Function to get all wishlist items. addonify_wishlist_get_wishlist_items(); // Function to get wishlist items count. addonify_wishlist_get_wishlist_items_count(); // Function to check if a product is in wishlist. $product_id is optional. addonify_wishlist_is_product_in_wishlist( $product_id = '' ); // Function to get add to wishlist button label. If $in_wishlist is set to true, added to wishlist button label will be returned. addonify_wishlist_get_button_label( $in_wishlist = false ); // Function to get link to the wishlist page. addonify_wishlist_get_wishlist_page_url();
Above functions about getting products, product count and checking if product is in wishlist only work when user is logged in as they are saved in database.
For non-logged-in users, wishlist data are saved locally. Following is a custom function in javascript available that you can use to obtain products in wishlist:
// Function to get all wishlist items. addonify_wishlist_get_wishlist_products();
There are also custom JavaScript event triggers that you can use.
// addonify_added_to_wishlist fires after a product is added to the wishlist. $(document).on('addonify_added_to_wishlist', function (event, [{ productID: $product_id, wishlist_count: $no_of_items_in_wishlist, sidebar_data: $html_appended_to_sidebar }]) {}); // addonify_added_to_wishlist fires after a product is removed from the wishlist. $(document).on('addonify_removed_from_wishlist', function (event, [{ productID: $product_id, wishlist_count: $no_of_items_in_wishlist }]) {});