Tagged: x
-
AuthorPosts
-
April 22, 2016 at 2:49 am #894918
AquorParticipantHi there,
I’d like to have a different navigation menu on my shop page. I used the code provided in another thread and it worked great, except it made the ‘navbar cart’ disappear on woocommerce pages.
Here is the code I added to functions.php:
add_filter( 'wp_nav_menu_args', 'woocommerce_menu' ); function woocommerce_menu( $args ) { if ( x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() || is_cart() || is_checkout() || is_account_page() ) { $args['theme_location'] = 'woocommerce'; } return $args; } register_nav_menus ( array( 'woocommerce' => __( 'Woocommerce Menu', '__x__' ) ) );Do you know if it’s possible to make the navbar cart reappear? If it could do the opposite (only appear on woocommerce pages), that would be even better.
Shop page I’m having trouble with: http://www.aquorwatersystems.com/shop
Thanks!
April 22, 2016 at 5:39 pm #895989
FriechModeratorHi There,
Thanks for writing in! Would you mind to clarify the issue? I’m seeing the navbar in every page on your site.
We’ll be happy to provide you with a response once we have a better understanding of the situation.Cheers!
April 22, 2016 at 5:54 pm #895998
AquorParticipantHi,
I went ahead and added the code snippet to my site – now you’ll see the nav cart missing.
Here is my entire functions.php:
<?php // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to X in this file. // ============================================================================= add_filter( 'woocommerce_order_button_text', create_function( '', 'return "Continue to Payment";' ) ); // Edit order items table template defaults function sww_add_wc_order_email_images( $table, $order ) { ob_start(); $template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php'; wc_get_template( $template, array( 'order' => $order, 'items' => $order->get_items(), 'show_download_links' => $show_download_links, 'show_sku' => $show_sku, 'show_purchase_note' => $show_purchase_note, 'show_image' => true, 'image_size' => $image_size ) ); return ob_get_clean(); } add_filter( 'woocommerce_email_order_items_table', 'sww_add_wc_order_email_images', 10, 2 ); // Show trailing zeros on prices, default is to hide it. add_filter( 'woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1 ); function wc_hide_trailing_zeros( $trim ) { // set to false to show trailing zeros return true; } 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 ); add_filter( 'wp_nav_menu_args', 'woocommerce_menu' ); function woocommerce_menu( $args ) { if ( x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() || is_cart() || is_checkout() || is_account_page() ) { $args['theme_location'] = 'woocommerce'; } return $args; } register_nav_menus ( array( 'woocommerce' => __( 'Woocommerce Menu', '__x__' ) ) ); ?>I can’t find what bit in the PHP is interfering – do you know what it could be?
April 23, 2016 at 9:32 pm #897086
Rue NelModeratorHello There,
The cart menu is missing because it is designed to show up in the primary menu. Since you modify the code and display a different menu, you also need to modify where the cart menu will appear. To do that, simply add this code to your child theme’s functions.php file
// Add cart menu to the primary and woocommerce custom menu // ============================================================================= 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' || $args->theme_location == 'woocommerce' ) { $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 ); // =============================================================================Please let us know if this works out for you.
April 27, 2016 at 2:38 pm #902899
AquorParticipantHi,
It worked great. Now the navbar cart appears everywhere on my site, thanks.
One last issue though: I had the navbar cart set to appear only when items were added, and hide when empty.
This code seems to work:
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 } }But it makes the cart appear for a split second while loading the page before hiding it — not a great user experience.
Is there a way to edit the php you provided to hide the navbar cart when empty? Thank you.
April 27, 2016 at 2:57 pm #902935
AquorParticipantNevermind! I was able to solve my own question. Thanks for your help anyway though.
If anyone else needs help doing the same thing, this small change is all that’s needed:
if ( $args->theme_location == 'primary' && WC()->cart->cart_contents_count > 0 || $args->theme_location == 'woocommerce' && WC()->cart->cart_contents_count > 0 ) {PS: If you know of a way to show only the inner navbar cart (the icon portion) until items are added to cart (then showing the full navbar cart with item count), that would be even better.
April 28, 2016 at 3:27 am #903688
Rue NelModeratorHello There,
To show the inner navbar cart icon until items are added to cart, please have your code updated and use this instead:
// Add cart menu to the primary and woocommerce custom menu // ============================================================================= function x_woocommerce_navbar_menu_item( $items, $args ) { if ( WC()->cart->cart_contents_count > 0 ) { $empty = 'has-cart-items'; } else { $empty = 'empty-cart'; } if ( X_WOOCOMMERCE_IS_ACTIVE && x_get_option( 'x_woocommerce_header_menu_enable' ) == '1' ) { if ( $args->theme_location == 'primary' || $args->theme_location == 'woocommerce' ) { $items .= '<li class="menu-item current-menu-parent x-menu-item x-menu-item-woocommerce">' . '<a href="' . x_get_cart_link() . '">' . x_woocommerce_navbar_cart() . '</a>' . '</li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'x_woocommerce_navbar_menu_item', 9999, 2 ); // =============================================================================And then you also need to add the following css code in the customizer, Appearance > Customize > Custom > CSS
.site .x-btn-navbar-woocommerce.empty-cart .x-cart .inner { display: none; } .site .x-btn-navbar-woocommerce.has-cart-items .x-cart .inner { display: block; }We would loved to know if this has work for you. Thank you.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-894918 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
