Wishlist for WooCommerce Shortcodes

Below, you’ll find a detailed guide on how to add the Wishlist for WooCommerce Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Wishlist for WooCommerce Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Wishlist for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Wishlist for WooCommerce

"Wishlist for WooCommerce is a dynamic plugin that allows users to create, manage, and share their product wishlists, enhancing user experience and boosting sales."

★★★★☆ (45) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 5.6.0
Included Shortcodes:
  • [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST]
  • [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT]
  • [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN]

Wishlist for WooCommerce [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST] Shortcode

The Wish List for WooCommerce shortcode allows users to add items to a wish list. It checks if the user is logged in and fetches the user ID. It also validates the user’s ability to remove items and displays the stock and price. .

Shortcode: [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST]

Parameters

Here is a list of all possible Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST shortcode parameters and attributes:

  • is_email – Determines if the wishlist is being displayed in an email. Default is ‘false’.
  • ignore_excluded_items – If set to ‘true’, items excluded from the wishlist will be ignored. Default is ‘true’.

Examples and Usage

Basic example – Display the default wishlist without any specific parameters.

[alg_wc_wish_list]

Advanced examples

Display the wishlist and specify whether to ignore excluded items or not. Here, we set the parameter ‘ignore_excluded_items’ to ‘false’ so it will not ignore excluded items.

[alg_wc_wish_list ignore_excluded_items='false']

Display the wishlist and specify whether it’s for an email or not. Here, we set the parameter ‘is_email’ to ‘true’ so it will be formatted for an email.

[alg_wc_wish_list is_email='true']

Display the wishlist with both ‘is_email’ and ‘ignore_excluded_items’ parameters. Here, the wishlist will not ignore excluded items and will be formatted for an email.

[alg_wc_wish_list is_email='true' ignore_excluded_items='false']

PHP Function Code

In case you have difficulties debugging what causing issues with [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST, array( Alg_WC_Wish_List_Shortcodes::get_class_name(), 'sc_alg_wc_wl' ) );

Shortcode PHP function:

function sc_alg_wc_wl( $atts ) {
			$atts = shortcode_atts( array(
				'is_email' => 'false',
                'ignore_excluded_items' => 'true'
			), $atts, self::SHORTCODE_WISH_LIST );

			$user_id_from_query_string = isset( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER ] ) ? sanitize_text_field( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER ] ) : '';
			$user_id                   = ! empty( $user_id_from_query_string ) ? Alg_WC_Wish_List_Query_Vars::crypt_user( $user_id_from_query_string, 'd' ) : null;
			$user_id                   = empty( $user_id ) ? $user_id_from_query_string : $user_id;
			$can_remove_items          = $user_id && Alg_WC_Wish_List_Unlogged_User::get_unlogged_user_id() != $user_id ? false : true;
			$show_stock                = filter_var( get_option( Alg_WC_Wish_List_Settings_List::OPTION_STOCK, false ), FILTER_VALIDATE_BOOLEAN );
			$show_price                = filter_var( get_option( Alg_WC_Wish_List_Settings_List::OPTION_PRICE, false ), FILTER_VALIDATE_BOOLEAN );
			$use_id_from_unlogged_user = isset( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER_UNLOGGED ] ) ? sanitize_text_field( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER_UNLOGGED ] ) : false;
			$use_id_from_unlogged_user = empty( $use_id_from_unlogged_user ) ? false : filter_var( $use_id_from_unlogged_user, FILTER_VALIDATE_BOOLEAN );
			$show_add_to_cart_btn      = filter_var( get_option( Alg_WC_Wish_List_Settings_List::OPTION_ADD_TO_CART_BUTTON, false ), FILTER_VALIDATE_BOOLEAN );
			$is_email                  = filter_var( $atts['is_email'], FILTER_VALIDATE_BOOLEAN );
			$ignore_excluded_items     = filter_var( $atts['ignore_excluded_items'], FILTER_VALIDATE_BOOLEAN );

			if ( is_user_logged_in() && $user_id == null ) {
				$user    = wp_get_current_user();
				$user_id = $user->ID;
			}

			$wishlisted_items = Alg_WC_Wish_List::get_wish_list( $user_id, $use_id_from_unlogged_user, $ignore_excluded_items );
			if ( is_array( $wishlisted_items ) && count( $wishlisted_items ) > 0 ) {
				$the_query = new WP_Query( array(
					'post_type'      => array( 'product', 'product_variation' ),
					'post_status'    => array( 'publish','trash' ),
					'posts_per_page' => - 1,
					'post__in'       => $wishlisted_items,
					'orderby'        => 'post__in',
					'order'          => 'asc'
				) );
			} else {
				$the_query = null;
			}

			$btn_params                          = Alg_WC_Wish_List_Toggle_Btn::get_toggle_btn_params();
			$btn_params['btn_class']             .= ' remove alg-wc-wl-remove-item-from-wl';
			$btn_params['remove_btn_icon_class'] = apply_filters( 'alg_wc_wl_fa_icon_class', '', 'remove_btn' );
			$params = array(
				'the_query'             => $the_query,
				'can_remove_items'      => $can_remove_items,
				'show_stock'            => $show_stock,
				'remove_btn_params'     => $btn_params,
				'show_add_to_cart_btn'  => $show_add_to_cart_btn,
				'show_price'            => $show_price,
				'is_email'              => $is_email
			);

			return alg_wc_wl_locate_template( 'wish-list.php', $params );
		}

Code file location:

wish-list-for-woocommerce/wish-list-for-woocommerce/includes/class-alg-wc-wish-list-core.php

Wishlist for WooCommerce [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT] Shortcode

The Wish-List-For-WooCommerce plugin shortcode is used to display the count of wishlisted items. It can ignore excluded items and handle user-specific queries. This PHP code executes the shortcode, allowing customization of the displayed count. It can differentiate between logged-in and unlogged users, ensuring accurate data representation.

Shortcode: [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT]

Parameters

Here is a list of all possible Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT shortcode parameters and attributes:

  • ignore_excluded_items – Skips items that are excluded from the wish list.
  • amount – Manually sets the number of wishlisted items.

Examples and Usage

Basic example – Displays the number of items in the wishlist of the current user.

[alg_wc_wl_counter]

Advanced examples

Display the number of items in the wishlist of the current user, ignoring items that have been excluded from the wishlist.

[alg_wc_wl_counter ignore_excluded_items=true]

Set a fixed number of items to be displayed in the wishlist counter, regardless of the actual number of items in the wishlist.

[alg_wc_wl_counter amount=10]

Display the number of items in the wishlist of the current user, ignoring items that have been excluded from the wishlist, and setting a fixed number of items to be displayed in the wishlist counter.

[alg_wc_wl_counter ignore_excluded_items=true amount=10]

PHP Function Code

In case you have difficulties debugging what causing issues with [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_COUNT, array( Alg_WC_Wish_List_Shortcodes::get_class_name(), 'sc_alg_wc_wl_counter' ) );

Shortcode PHP function:

function sc_alg_wc_wl_counter( $atts ) {
			$atts = shortcode_atts( array(
				'ignore_excluded_items' => 'false',
				'amount' => '',
			), $atts, self::SHORTCODE_WISH_LIST_COUNT );
			$ignore_excluded_items = filter_var( $atts['ignore_excluded_items'], FILTER_VALIDATE_BOOLEAN );

			if ( empty( $atts['amount'] ) ) {
				$user_id_from_query_string = get_query_var( Alg_WC_Wish_List_Query_Vars::USER, null );
				$user_id                   = ! empty( $user_id_from_query_string ) ? Alg_WC_Wish_List_Query_Vars::crypt_user( $user_id_from_query_string, 'd' ) : null;
				$use_id_from_unlogged_user = filter_var( get_query_var( Alg_WC_Wish_List_Query_Vars::USER_UNLOGGED, false ), FILTER_VALIDATE_BOOLEAN );
				if ( is_user_logged_in() && $user_id == null ) {
					$user    = wp_get_current_user();
					$user_id = $user->ID;
				}

				$wishlisted_items = Alg_WC_Wish_List::get_wish_list( $user_id, $use_id_from_unlogged_user, $ignore_excluded_items );
				$amount = is_array( $wishlisted_items ) ? count( $wishlisted_items ) : 0;
			} else {
				$amount = $atts['amount'];
			}
			return "<span class='alg-wc-wl-counter'>$amount</span>";
		}

Code file location:

wish-list-for-woocommerce/wish-list-for-woocommerce/includes/class-alg-wc-wish-list-core.php

Wishlist for WooCommerce [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN] Shortcode

The Wish List for WooCommerce shortcode is a powerful tool that allows users to remove all items from their wish list with a single click. This shortcode generates a button that, when clicked, clears all items from the user’s wish list. It offers customizable options like button tag, class, and label. The ‘auto_hide’ feature hides the button when the wish list is empty. It also supports a loading icon during processing.

Shortcode: [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN]

Parameters

Here is a list of all possible Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN shortcode parameters and attributes:

  • show_loading – shows a loading icon when set to true.
  • tag – defines the HTML tag for the button, default is ‘button’.
  • btn_class – assigns CSS classes to the button.
  • remove_label – sets the button’s text, default is ‘Remove all’.
  • auto_hide – hides the button when there are no items in the wish list if set to true.

Examples and Usage

Basic example – A simple usage of the shortcode to display a “Remove all” button for the WooCommerce wish list.

[alg_wc_wl_remove_all_btn /]

Advanced examples

Displaying a “Remove all” button with specific class and tag, and with the loading spinner enabled.

[alg_wc_wl_remove_all_btn show_loading=true tag="div" btn_class="my-remove-all-button-class" /]

Changing the label of the “Remove all” button and enabling the auto-hide feature when there are no items in the wish list.

[alg_wc_wl_remove_all_btn remove_label="Delete all items" auto_hide=true /]

Combining multiple parameters to customize the “Remove all” button. This example changes the button tag to a div, applies a custom class, changes the button label, enables the loading spinner, and enables the auto-hide feature.

[alg_wc_wl_remove_all_btn show_loading=true tag="div" btn_class="my-custom-class" remove_label="Clear wish list" auto_hide=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( Alg_WC_Wish_List_Shortcodes::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN, array( Alg_WC_Wish_List_Shortcodes::get_class_name(), 'sc_alg_wc_wl_remove_all_btn' ) );

Shortcode PHP function:

function sc_alg_wc_wl_remove_all_btn( $atts = null ) {
			$atts = shortcode_atts( array(
				'show_loading' => false,
				'tag'          => 'button',
				'btn_class'    => 'alg-wc-wl-btn2 alg-wc-wl-remove-all',
				'remove_label' => apply_filters( 'alg_wc_wl_remove_all_btn_label', __( 'Remove all', 'wish-list-for-woocommerce' ) ),
				'auto_hide'    => false
			), $atts, self::SHORTCODE_WISH_LIST_REMOVE_ALL_BTN );
			$auto_hide_param = $atts['auto_hide'] ? 'data-auto_hide="true"' : '';
			if ( $auto_hide_param ) {
				$user_id_from_query_string = isset( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER ] ) ? sanitize_text_field( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER ] ) : '';
				$user_id                   = ! empty( $user_id_from_query_string ) ? Alg_WC_Wish_List_Query_Vars::crypt_user( $user_id_from_query_string, 'd' ) : null;
				$user_id                   = empty( $user_id ) ? $user_id_from_query_string : $user_id;
				$use_id_from_unlogged_user = isset( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER_UNLOGGED ] ) ? sanitize_text_field( $_REQUEST[ Alg_WC_Wish_List_Query_Vars::USER_UNLOGGED ] ) : false;
				$use_id_from_unlogged_user = empty( $use_id_from_unlogged_user ) ? false : filter_var( $use_id_from_unlogged_user, FILTER_VALIDATE_BOOLEAN );
				if ( is_user_logged_in() && $user_id == null ) {
					$user    = wp_get_current_user();
					$user_id = $user->ID;
				}
				$wishlisted_items = Alg_WC_Wish_List::get_wish_list( $user_id, $use_id_from_unlogged_user );
				if ( empty( $wishlisted_items ) ) {
					return apply_filters( 'alg_wc_wl_remove_all_btn_html', '' );
				}
			}
			ob_start();
			?>
            <<?php echo esc_attr( $atts['tag'] ) ?> <?php echo $auto_hide_param; ?> class="<?php echo esc_attr( $atts['btn_class'] ); ?>">
            <span class="alg-wc-wl-btn-text"><?php echo esc_html( $atts['remove_label'] ); ?></span>
			<?php if ( $atts['show_loading'] ): ?>
                <i class="loading fas fa-sync-alt fa-spin fa-fw"></i>
			<?php endif; ?>
            </<?php echo esc_attr( $atts['tag'] ) ?>>
			<?php

			return apply_filters( 'alg_wc_wl_remove_all_btn_html', ob_get_clean() );
		}

Code file location:

wish-list-for-woocommerce/wish-list-for-woocommerce/includes/class-alg-wc-wish-list-core.php

Conclusion

Now that you’ve learned how to embed the Wishlist for WooCommerce Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *