Changing Title of 0 Items
-
Thanks for the plugin.
How do I change the title of the menu item from “0 Items” to say “Buy Services.” This can then change to the normal # Items depending on the items in the cart.
Thanks.
-
Hello Harvoolio,
You can do this by adding the following code to your themes functions.php:add_filter( 'wpmenucart_menu_item_a_content', 'wpmenucart_empty_display_text', 10, 4 ); function wpmenucart_empty_display_text ( $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data ) { if ($item_data['cart_contents_count'] == 0) { $menu_item_a_content = '<span class="wpmenucart-empty-display">Buy Services.</span>'; } return $menu_item_a_content; }
Thanks.
As an FYI the same issue remains as it did for the callout text changing “view your shopping cart” and “start shopping”.
If I put the code in above the following scenarios happen:
1 – Enter the website – shows “Buy Services.” – works.
2 – Click “Buy Services” and Buy an item – changes to “1 Item” – works
3 – Go to Checkout and Remove an item from checkout – shows “O Items” – does not work. Should revert to Buy Services.
4 – Click 0 Items – reverts to Buy Services but only after clicking the item.Thanks.
Hello Harvoolio,
I have no idea why this happens… It’s so strange because with the code above, the text ‘0 items’ should actually never receive the front-end at all! Are you sure this is not just retrieved from cache somewhere? Does the same thing happen when you open the site in an incognito/private browser window?Let me know!
EwoutFirst, let me preface this by saying the bug is very inconsequential (I am just trying to help debug). I love the plugin.
If this helps, my site is hosted at Flywheel on a NGINX server (they handle caching).
I just tested it in incognito mode and the same thing happened.
As I am learning more about coding, I decided to revisit the issue. I took a look at what happens to the html classes in all 3 scenarios. If everything were working the html should look exactly the same in scenarios 1 and 3. But there is one difference. I think the issue is that although the
<a>
class is changed to wpmenucart-empty-display, the <span> class is not likewise changed to wpmenucart-empty-display.Here is what the html looks like in scenario 1 (works) upon entering the site.
<li class="wpmenucarli wpmenucart-display-standard menu-item" id="wpmenucartli"> <a class="wpmenucart-contents empty-wpmenucart-visible" href="URL/mba-admissions-consulting-services/" title="Buy admissions consulting services"> <span class="wpmenucart-empty-display">Buy</span> </a> </li>
Here is what the html looks like in scenario 2 (works) upon buying an item.
<li class="wpmenucarli wpmenucart-display-standard menu-item" id="wpmenucartli"> <a class="wpmenucart-contents" href="URL/checkout/" title="Go to checkout"> <i class="wpmenucart-icon-shopping-cart-0"> ::before </i> <span class="cartoncontents">1 item</span> </a> </li>
Here is what the html looks like in scenario 3 (does not work) upon removing an item.
<li class="wpmenucarli wpmenucart-display-standard menu-item" id="wpmenucartli"> <a class="wpmenucart-contents empty-wpmenucart-visible" href="URL/mba-admissions-consulting-services/" title="Buy admissions consulting services"> <i class="wpmenucart-icon-shopping-cart-0"> ::before </i> <span class="cartoncontents">0 items</span> </a> </li>
You can see that the code which adds class “empty-wpmenucart-visible” to
<a>
class works upon removing the item, but the subsequent code (or parallel code) that removes the i tag and “cartoncontents” from span is not working.Here are some wild suggestions. I am looking at wp-menu-cart.php and I see lines 445-454. I am running case 1. Do you think there needs to be an if conditional.
Even if I remark out the suggested php from a few weeks ago the issue is not that code but rather the code in wp-menu-cart.php is not removing the i tag and swapping “empty-wpmenucart-visible” for “cartoncontents” when the last item is removed from woocommerce checkout (hence making there no items).
I hope I explained this well.
</a>
I am about to launch my application live and am revisiting all open issues prior to the application’s release. Has this been addressed?
Thanks.
Hello Harvoolio,
Can you post a URL to the site so we can check it out? I haven’t been able to replicate this error. The if conditional is already there, in your filter! The filter is executed much later en replaces (or should replace) all that HTML entirely. I think this is some sort of caching issue playing up.Ewout
The site is about to go public, but not yet. It resides on Flywheel which has a username and password. I just added support at wpovernight.com (written this way to avoid sending you SPAM) as a collaborator. Let me know if you can access the site. All you need to do is select an item to purchase, go to Checkout and remove it. You will then see how WPMenucart is not updated.
Thanks.
This is now solved – it turned out to be theme specific.
Some themes disable functions.php for the backend, in order to prevent a complete lockout. The way they do this, is by simply doing an is_admin() check. However, since all AJAX is ran through admin-ajax.php, this returns true, and the theme functions are not loaded and filters will not be applied (!). In this particular case (Genesis Framework w. Dynamik website builder) there was a setting to enable the theme functions in the backend too, and this solved the issue.
Ewout
- The topic ‘Changing Title of 0 Items’ is closed to new replies.