Bricks Boilerplate Documentation
PricingDemo
  • Intro
  • Getting Started
    • Requirements
    • 5 minutes launch ⚡
    • Import into an existing project
  • Basics
    • Inside the package
    • Global Styles
      • General
      • CSS Variables
      • Buttons
      • Utility classes
    • Templates
    • ACF
      • Global topbar
    • Bricks Boilerplate Addon plugin
      • Wishlist
      • Variation swatches
      • Checkout
    • Code snippets
  • Tutorials
    • Blog in 5 minutes
    • Custom Off-canvas cart
    • Off-canvas cart without addon plugin
    • Custom Thank you page
    • Custom Checkout page
    • Custom Cart page
    • My account page
    • Product gallery with thumbnails
    • Custom query for product reviews
  • Advanced
    • Custom slider controls
    • Custom accordions
    • Megamenu
    • GSAP animations
  • Common issues
    • Custom CSS
    • Product galleries
    • Restoring site with WPvivid
Powered by GitBook
On this page
  • Creating a list of favorite posts
  • Showing dynamic number indicating number of favorite posts
  1. Basics
  2. Bricks Boilerplate Addon plugin

Wishlist

PreviousBricks Boilerplate Addon pluginNextVariation swatches

Last updated 7 months ago

This feature comes with an Element "Wishlist" that is meant to be used inside a query loop. With this you can let users save favorite posts (products).

You can control default and active icon states easily:

Creating a list of favorite posts

If user is not logged in - favorite posts are stored in a local storage. If they are logged in, favorite posts are tied to their account. Use this custom code to query them (Query editor - PHP) - in this case its for products:

$wishlist_items = brtheme_get_wishlist_items();
if ( empty( $wishlist_items ) ) {
 return [
  'post_type' => 'product',
  'posts_per_page' => -1,
   'post__in' => [-1]
  ];
}
return [
  'post_type' => 'product',
  'posts_per_page' => -1,
  'post__in' => $wishlist_items
  ];

Showing dynamic number indicating number of favorite posts

<?php
// Get wishlist items
$wishlist_items = brtheme_get_wishlist_items();

// Count the number of items in the wishlist
$wishlist_count = count($wishlist_items);

// Output the number of wishlist items
echo '<span class="brt-wishlist-items-count">' . $wishlist_count . '</span>';

// Check if the wishlist is empty and set query arguments accordingly
if ( empty( $wishlist_items ) ) {
    // Return empty result if no items in the wishlist
    $query_args = [
        'post_type'      => 'product',
        'posts_per_page' => -1,
        'post__in'       => [-1]
    ];
} else {
    // Return wishlist items query
    $query_args = [
        'post_type'      => 'product',
        'posts_per_page' => -1,
        'post__in'       => $wishlist_items
    ];
}
?>

Make sure that the returned element has this class: "brt-wishlist-items-count" which will update our number via AJAX.

Sometimes we want to display this: and update the number every time post is being added to wishlist. We can use simple PHP function to retrieve this number: