-
AuthorPosts
-
October 16, 2015 at 12:17 pm #628225
I love the super cool looking WooCommerce cart in the menu — the integration is awesome… but it is confusing my members to have the cart visible when there are no items in it.
Is there some way to hide this cart when there is nothing in it?
Thanks!
October 16, 2015 at 12:48 pm #628254Hello Chad,
Thanks for writing in!
Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. Having said that X theme is fully compatible with WooCommerce but we can’t change the core functionality of the plugin since developers of WooCommerce update the plugin regularly and some of the update might compatibility issues. But I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here. We request you to kindly walk-through following thread:
https://wordpress.org/support/topic/make-it-hide-with-0
Thank you for your understanding.
October 17, 2015 at 12:09 pm #629335What file in the X theme handles the output of this cart? I can’t seem to find it — to override.
Thanks.
October 17, 2015 at 12:40 pm #629370Hi There,
Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.
Add this code at your child theme’s functions.php
add_action( 'wp_footer', 'x_hide_cart' ); function x_hide_cart(){ if ( WC()->cart->get_cart_contents_count() == 0 ) { ?> <style type="text/css">.x-menu-item-woocommerce{display: none;}</style> <?php } }
Hope this helps.
October 17, 2015 at 1:21 pm #629401I found it… and actually, this is something you could probably build into the customizer. In woocommerce.php, I used
WC()->cart->cart_contents_count
(which you already used in the same location).I simply wrapped the output, to only output if there are more than 0 items in the cart:
if (WC()->cart->cart_contents_count > 0) { return $cart_output; }
Thanks!
October 17, 2015 at 10:49 pm #629658Hi Chad,
We certainly appreciate the feedback! This is something we can add to our list of feature requests. This way it can be taken into consideration for future development. All of these items are discussed with our team internally and prioritized based on the amount of interest a particular feature might receive. Thanks!
If you did some changes in woocommerce.php file, those changes will be overwritten when an X update is released. It is not safe. Please make sure that all your customizations is being placed inside your child theme’s functions.php file. For this issue, you can also make use of this code in your child theme’s functions.php file
// // Outputs a navigation item with the cart. // if ( ! function_exists( 'x_woocommerce_navbar_menu_item' ) ) : function x_woocommerce_navbar_menu_item( $items, $args ) { if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( 'x_woocommerce_header_menu_enable', '' ) == '1' ) { if ( $args->theme_location == 'primary' && WC()->cart->cart_contents_count > 0 ) { $items .= '<li class="menu-item current-menu-parent x-menu-item x-menu-item-woocommerce">' . '<a href="' . x_get_cart_link() . '" class="x-btn-navbar-woocommerce">' . x_woocommerce_navbar_cart() . '</a>' . '</li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'x_woocommerce_navbar_menu_item', 9999, 2 );
Hope this helps. Please let us know how it goes.
April 13, 2016 at 2:55 am #879554I’m sorry – I had the same question and pasted your code on functions.php,
but this gives an unexpected end of line error. I think some brackets are missing (?)April 13, 2016 at 3:06 am #879562Chad had just a simple line of code:
if (WC()->cart->cart_contents_count > 0) {
return $cart_output;
}But i cannot seem to find out where to put this code in woocommerce.php..
April 13, 2016 at 8:13 am #879957Hi,
Sorry, there was a syntax error in the code.
You can try this instead.
function x_woocommerce_navbar_menu_item( $items, $args ) { if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( 'x_woocommerce_header_menu_enable', '' ) == '1' ) { if ( $args->theme_location == 'primary' && WC()->cart->cart_contents_count > 0 ) { $items .= '<li class="menu-item current-menu-parent x-menu-item x-menu-item-woocommerce">' . '<a href="' . x_get_cart_link() . '" class="x-btn-navbar-woocommerce">' . x_woocommerce_navbar_cart() . '</a>' . '</li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'x_woocommerce_navbar_menu_item', 9999, 2 );
Hope that helps.
April 19, 2016 at 11:40 am #890379Is there a specific place to put it in woocommerce.php? or just at the end?
April 19, 2016 at 11:56 pm #891205Hi,
You need to add the code in your child theme’s functions.php file located at wp-content/themes/x-child
Please add it after this line
// Additional Functions
// =============================================================================May 17, 2016 at 4:20 am #995138If i copy the code and put it in the functions.php of the Child theme, I get an error:
Parse error: syntax error, unexpected end of file in /home/bpr.nu/public_html/koot15.nl/wp-content/themes/x-child/functions.php on line 38Any idea how to fix this?
So, my file contains:
<?php// =============================================================================
// FUNCTIONS.PHP
// —————————————————————————–
// Overwrite or add your own custom functions to X in this file.
// =============================================================================// =============================================================================
// TABLE OF CONTENTS
// —————————————————————————–
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================// Enqueue Parent Stylesheet
// =============================================================================add_filter( ‘x_enqueue_parent_stylesheet’, ‘__return_true’ );
// Additional Functions
// =============================================================================function x_woocommerce_navbar_menu_item( $items, $args ) {
if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( ‘x_woocommerce_header_menu_enable’, ” ) == ‘1’ ) {
if ( $args->theme_location == ‘primary’ && WC()->cart->cart_contents_count > 0 ) {
$items .= ‘<li class=”menu-item current-menu-parent x-menu-item x-menu-item-woocommerce”>’
. ‘‘
. x_woocommerce_navbar_cart()
. ‘‘
. ‘‘;
}
}return $items;
May 17, 2016 at 5:25 am #995180Hi there,
Please update your code to :
<?php // ============================================================================= // FUNCTIONS.PHP // —————————————————————————– // Overwrite or add your own custom functions to X in this file. // ============================================================================= // ============================================================================= // TABLE OF CONTENTS // —————————————————————————– // 01. Enqueue Parent Stylesheet // 02. Additional Functions // ============================================================================= // Enqueue Parent Stylesheet // ============================================================================= add_filter( 'x_enqueue_parent_stylesheet', '__return_true' ); // Additional Functions // ============================================================================= function x_woocommerce_navbar_menu_item( $items, $args ) { if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( 'x_woocommerce_header_menu_enable', '' ) == '1' ) { if ( $args->theme_location == 'primary' && WC()->cart->cart_contents_count > 0 ) { $items .= '<li class="menu-item current-menu-parent x-menu-item x-menu-item-woocommerce">' . '<a href="' . x_get_cart_link() . '" class="x-btn-navbar-woocommerce">' . x_woocommerce_navbar_cart() . '</a>' . '</li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'x_woocommerce_navbar_menu_item', 9999, 2 );
Hope it helps.
May 25, 2016 at 11:16 am #1009319Thanks Christopher, you ROCK!
May 25, 2016 at 12:20 pm #1009455Glad we could help 🙂
Cheers!
-
AuthorPosts