5 Programming Queries and Their Answers on WooCommerce Wishlist Plugin - Part 1

WooCommerce Wishlist plugin is one of the most useful plugins for any eCommerce website based on WooCommerce and WordPress. This is a simple plugin which you can download from FMEAddons and can easily integrate with your web based store. However, there are some new users who often face problems at different stages while using or installing Wishlist functionality on their store. Looking on this, we have prepared the following list of frequently asked questions by end users regarding WooCommerce Wishlist plugin with detailed answers. The questions which are given below are equally helpful for both new and experienced users of WooCommerce.

Important Note:

These are the answers provided by the community and best rated by the community as well. 

Question 1:

How to populate WooCommerce SKU on Wishlist?

The User wants to get the unique SKU from the product detail page to populate wishlist, the wishlist.php contains code:

<?php if( get_option( 'yith_wcwl_stock_number_show' ) == 'yes' ) : ?>
                        <td class="product-stock-number">
                            <?php echo $product->get_sku(); ?>
                    <?php endif ?>

$product is global variable i.e.

global $product;

User get Fatal error which is given below

Fatal error: Call to a member function get_sku() on a non-object in /home2/cityrank/public_html/wp-content/plugins/woocommerce-wishlist/templates/wishlist.php on line 142

The price code is:

<?php if( get_option( 'yith_wcwl_price_show' ) == 'yes' ) : ?>
                        <td class="product-price">
                            if( $product_obj->price != '0' ) {
                                if( get_option( 'woocommerce_tax_display_cart' ) == 'excl' )
                                    { echo apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_obj->get_price_excluding_tax() ), $values, '' ); }
                                    { echo apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_obj->get_price() ), $values, '' ); }
                            } else {
                                echo apply_filters( 'yith_free_text', __( 'Free!', 'yit' ) );
                    <?php endif ?>


Looking at your code I would suggest you add


Currently it seems like data is not loaded to the $product, but instead using $product_obj(etc.)

Question 2:

How to edit wishlist of current user?

Users are not able to edit their wishlist profile by clicking on 'edit wishlist' button when the user tries to click on the button it returns an error saying the wish list id not found, but actually, it is the user.id, not the wishlist.id. The user is asking for its solution.

The code is given below

<div class="post3">
    <h1><%= t('.mwg')%></h1><br />
    <div id = "table-2">
    <table width="240" >
        <% Wishlist.where(:user_id => @user).each do |wishlist| %>
        <tr><td width="30"><b>1:</b></td><td><%= wishlist.number_1 %></td></tr>
        <tr><td width="30"><b>2:</b></td><td><%= wishlist.number_2 %></td></tr>
        <tr><td width="30"><b>3:</b></td><td><%= wishlist.number_3 %></td></tr>
        <tr><td width="30"><b>4:</b></td><td><%= wishlist.number_4 %></td></tr>
        <tr><td width="30"><b>5:</b></td><td><%= wishlist.number_5 %></td></tr>
    <%if current_user %>
       <% if current_user.id == wishlist.user_id %>
         <div id="text3"><%= link_to t('.edit'), edit_wishlist_path(@wishlist) %></div><br />

The user tried to change current_user.id == wishlist.user_id the line to the following:

<% if current_user.id == @wishlist.user_id %>

But getting the same error of undefined method user_id

Currently, the code returns the wishlist_id, but user wants to return the user_id


You just need to call edit_wishlist_path(wishlist), not @wishlist.

Question 3

The wishlist section disappears from the site when all items removed from it, User want to show wishlist section even if there is no item in it with a text "Add some items to your wishlist" how to do it?

User tried the .phtml file for solving the issue, but it is not working


In the newer versions after 1.4.2 the wishlist class has been changed, the new class is:

* @deprecated after
     * @see Mage_Wishlist_Block_Links::__construct
     * @return array
    public function addWishlistLink()
        return $this;

The above code is just for general information; the actual code which may solve your issue is given below

     * Add link on wishlist page in parent block
     * @return Mage_Wishlist_Block_Links
    public function addWishlistLink()
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && $this->helper('wishlist')->isAllow()) {
            $count = $this->helper('wishlist')->getItemCount();
            if ($count > 1) {
                $text = $this->__('My Wishlist (%d items)', $count);
            else if ($count == 1) {
                $text = $this->__('My Wishlist (%d item)', $count);
            else {
                $text = $this->__('My Wishlist');
            $parentBlock->addLink($text, 'wishlist', $text, true, array(), 30, null, 'class="top-link-wishlist"');
        return $this;

Question 4

The user has a custom wishlist plugin and a step by step form where users can choose a number of lists (1 to 10) as well as enter title and descriptions for lists, at the end, there is an Ajax request on the form. The user wants to add these generated lists to the database.

User tried  wp_insert_post( $my_post ), but it did’nt work.


You can try this if the code mentioned above is not working for you


Question 5

I have a Wishlist plugin code is written in Javascript. The plugin adds wishlist items successfully in the list but doesn't display any confirmation/success message after adding an item in the wishlist.

The user using the code given below for displaying success message, but it does not work

function AddItem(ToDoItem) {
    if ((ToDoItem != null) && (ToDoItem != "undefined" )) {
        SetCookie('PT_ToDoItem'+NumToDoItems, ToDoItem, exp);
        SetCookie('PT_NumToDoList',NumToDoItems, exp);
        $(window).humanMsg('Added '+ToDoItem+' to Wishlist');

How to resolve this issue?

The HTML code is:

<div class="add-to-wishlist">
<a href="javascript:AddItem('<?php print htmlentities($title, ENT_QUOTES); ?>')">
<img class="add-to-wishlist" src="/images/add-to-wishlist-button.gif" border="0" /></a>

jQuery file

(function($, window){

$.fn.humanMsg = function( message, options ) {
    return this.each(function(){
        var container = this == window || this == document ? document.body : this;
        !$.data(container, 'humanMsg') && $.data(container, 'humanMsg', new     $.humanMsg (container, message, options) );

$.humanMsg = function( container, message, options ) {
    if (typeof message == 'object') {
    options = message;
    message = null;

var s = $.extend({}, $.humanMsg.defaults, options);

var $m,
    sizeContainer = container == document.body ? window : container;

$m = $('<div class="humanized-message '+s.addClass+'"/>')
.html(message || s.message)

    display: 'none',
    visibility: 'visible',
    top: ($(sizeContainer).height()-$m.innerHeight())/2,
    left: ($(sizeContainer).width()-$m.innerWidth())/2

s.autoHide && setTimeout(remove, s.autoHide);   

function remove() {
    $m.fadeOut(s.speed, function(){
        $.removeData(container, 'humanMsg');


$.humanMsg.defaults = {
message: 'no message was set',
autoHide: 3000,
addClass: '',
speed: 300

})(jQuery, this);

Below is the error that occurs instead of showing success message

Uncaught TypeError: Property '$' of object [object Window] is not a function 
(anonymous function)
closing script tag manually 


Looking on the error, it indicates that your jQuery file is not included in the script, please have a look on your jQuery file


Download Woocommerce Wishlist Plugin


Leave a Reply