5 Programming Queries and Their Answers on WooCommerce Wishlist Plugin - Part 1
January 20, 2017,
Important Note: These are the answers provided by the community and best rated by the community as well.
$product is global variable i.e.php if( get_option( 'yith_wcwl_stock_number_show' ) == 'yes' ) : ?>
class="product-stock-number"> php echo $product->get_sku(); ?> php endif ?>
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:global $product;
php if( get_option( 'yith_wcwl_price_show' ) == 'yes' ) : ?>
class="product-price"> php 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, '' ); } else { 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 ?>
Currently it seems like data is not loaded to the $product, but instead using $product_obj(etc.)$product_obj->get_sku();
class="post3"> <%= t('.mwg')%>
/>id = "table-2"><%if current_user %> <% if current_user.id == wishlist.user_id %>width="240" > <% Wishlist.where(:user_id => @user).each do |wishlist| %>
width="30">1: <%= wishlist.number_1 %> width="30">2: <%= wishlist.number_2 %> width="30">3: <%= wishlist.number_3 %> width="30">4: <%= wishlist.number_4 %> width="30">5: <%= wishlist.number_5 %> id="text3"><%= link_to t('.edit'), edit_wishlist_path(@wishlist) %>
/> <%end%> <%end%> <%end%>The user tried to change current_user.id == wishlist.user_id the line to the following:
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<% if current_user.id == @wishlist.user_id %>
Answer:
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 workingAnswer:
In the newer versions after 1.4.2 the wishlist class has been changed, the new class is:The above code is just for general information; the actual code which may solve your issue is given below* @deprecated after 1.4.2.0 * @see Mage_Wishlist_Block_Links::__construct * * @return array */ public function addWishlistLink() { return $this; }
/** * 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.Answer:
You can try this if the code mentioned above is not working for youWC_Wishlists_Wishlist::create_list($tittle));
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 workHow to resolve this issue? The HTML code is:function AddItem(ToDoItem) { if ((ToDoItem != null) && (ToDoItem != "undefined" )) { NumToDoItems++; SetCookie('PT_ToDoItem'+NumToDoItems, ToDoItem, exp); SetCookie('PT_NumToDoList',NumToDoItems, exp); $(window).humanMsg('Added '+ToDoItem+' to Wishlist'); } }
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 = $('