Homepage › Forum › Product Support › Canifa › Minicart in nav
Tagged: mini-cart
This topic contains 8 replies, has 2 voices, and was last updated by trinhnv 7 years, 2 months ago.
-
AuthorPosts
-
7 years, 3 months ago #2010
AnonymousTopics: 8
Posts: 14Hi, I would like to make one change.
I would like the minicart, in the main navigation to appear when there are products added to it. In other words, I do not want it to be visible, if there is nothing in it. Please provide the code-snippet to make this happen.
7 years, 3 months ago #2013Hi borge77,
Thank you for your feedback.
I feel the appearance of the minicart is familiar to users, even when no items.
But if you want to change it, you can do the following:
1. Go to
{root}/wp-content/themes/yolo-canifa/includes/woocommerce.phpabout 90 lines to 107 lines
add to code:- old code:
$cart_has_items = ''; if ( $cart_count != "0" ) { $cart_has_items = ' has-items'; } $output = ''; if ( ! $content ) { $output .= '
- . esc_html__( 'View cart', 'yolo-motor' ) . '" class="cart-button" href="' . $woocommerce->cart->get_cart_url() . '">' . '. $cart_has_items . '">'; if ( $cart_count != "0" ) { $output .= "" . $cart_count . ""; } $output .= ''; $output .= ''
; $output .= ''; }Change to:
$cart_has_items = ''; $cart_no_items = ''; if ( $cart_count != "0" ) { $cart_has_items = ' has-items'; } if ( $cart_count <= 0 ) { $cart_no_items = ' no-items'; } $output = ''; if ( ! $content ) { $output .= '
- . $cart_no_items . '">. esc_html__( 'View cart', 'yolo-canifa' ) . '" class="cart-button" href="' . $woocommerce->cart->get_cart_url() . '">' . '. $cart_has_items . '">'; if ( $cart_count != "0" ) { $output .= "" . $cart_count . ""; } $output .= ''; $output .= ''; $output .= '
'; }Or you see in attachment.
2. Go to
{root}/wp-content/themes/yolo-canifa/assets/css/yolo.css
Add this code at the end of the file:
.yolo-main-menu .navbar-nav > li.menu-item.no-items{ display: none !important; }
Please try and if not true, contact for us.
----------------
Best regards,
trinhnv
Attachments:
You must be logged in to view attached files.7 years, 2 months ago #2016
AnonymousTopics: 8
Posts: 14Great, it worked, but how can I implement this in the child theme, or is this at all possible?
7 years, 2 months ago #2017Hi borge77,
Thank you for your feedback.
If you want to modify in child theme, you can do the following:
All attachments is in child-theme.
1. Go to
{root}/wp-content/themes/yolo-canifa/includes/woocommerce.php
find to function yolo_minicart( $content = false ){...}, about 83 lines.
You wrap it in clause if
if ( !function_exists( 'yolo_minicart' )) { function yolo_minicart( $content = false ) {...} }
or you can see attachment
2. Go to your child-theme
{root}/wp-content/themes/yolo-canifa-child/functions.php
add this code:
require_once( get_stylesheet_directory() . '/includes/woocommerce.php' );
3. Go to
{root}/wp-content/themes/yolo-canifa-child/includes/woocommerce.php
if not yet yolo-canifa-child/includes/woocommerce.php, you have to create it.
and add this code into this file:
<?php if ( class_exists( 'woocommerce' ) ) { // Menu cart if ( !function_exists( 'yolo_minicart' )) { function yolo_minicart( $content = false ) { global $woocommerce; $cart_output = ""; $cart_total = $woocommerce->cart->get_cart_total(); $cart_count = $woocommerce->cart->cart_contents_count; $cart_count_text = yolo_product_items_text( $cart_count ); $cart_has_items = ''; $cart_no_items = ''; if ( $cart_count != "0" ) { $cart_has_items = ' has-items'; } if ( $cart_count <= "0" ) { $cart_no_items = ' no-items'; } $output = ''; if ( ! $content ) { $output .= '
- . $cart_no_items . '">. esc_html__( 'View cart', 'yolo-canifa' ) . '" class="cart-button" href="' . $woocommerce->cart->get_cart_url() . '">' . '. $cart_has_items . '">'; if ( $cart_count != "0" ) { $output .= "" . $cart_count . ""; } $output .= ''; $output .= ''; $output .= '
'; } return $output; } } }'; } if ( $cart_count != "0" ) { $output .= ''. $cart_count_text . ' ' . esc_html__( 'in the shopping cart', 'yolo-canifa' ) . ''; $output .= ''; foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $cart_item ) { $cart_product = $cart_item['data']; $product_title = $cart_product->get_title(); $product_short_title = ( strlen( $product_title ) > 25 ) ? substr( $product_title, 0, 22 ) . '...' : $product_title; if ( $cart_product->exists() && $cart_item['quantity'] > 0 ) { $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''. esc_html__( "Price", "woocommerce" ) . ' ' . woocommerce_price( $cart_product->get_price() ) . ''; $output .= ''. esc_html__( 'Quantity', 'yolo-canifa' ) . ' ' . $cart_item['quantity'] . ''; $output .= ''; $output .= apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '×', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), esc_html__( 'Remove this item', 'yolo-canifa' ) ), $cart_item_key ); $output .= ''; } } $output .= ''; $output .= ''; $output .= ''. esc_html__( 'Cart Subtotal', 'yolo-canifa' ) . ' ' . $cart_total . ''; $output .= ''; if ( version_compare( WOOCOMMERCE_VERSION, "2.1.0" ) >= 0 ) { $cart_url = apply_filters( 'woocommerce_get_checkout_url', WC()->cart->get_cart_url() ); $checkout_url = apply_filters( 'woocommerce_get_checkout_url', WC()->cart->get_checkout_url() ); $output .= '. esc_url( $cart_url ) . '">' . esc_html__( 'View Cart', 'yolo-canifa' ) . ''; $output .= '. esc_url( $checkout_url ) . '">' . esc_html__( 'Checkout', 'yolo-canifa' ) . ''; } else { $output .= '. esc_url( $woocommerce->cart->get_cart_url() ) . '">' . esc_html__( 'View Cart', 'yolo-canifa' ) . ''; $output .= '. esc_url( $woocommerce->cart->get_checkout_url() ) . '">' . esc_html__( 'Checkout', 'yolo-canifa' ) . ''; } $output .= ''; $output .= ''; } else { $output .= ''. esc_html__( 'Your shopping bag is empty.', 'yolo-canifa' ) . ''; $shop_page_url = ""; if ( version_compare( WOOCOMMERCE_VERSION, "2.1.0" ) >= 0 ) { $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) ); } else { $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) ); } $output .= ''; $output .= ''; $output .= '. esc_url( $shop_page_url ) . '">' . esc_html__( 'Go to the shop', 'yolo-canifa' ) . ''; $output .= ''; $output .= ''; } if ( ! $content ) { $output .= ''; $output .= '4. Go to
{root}/wp-content/themes/yolo-canifa-child/style.css
if not yet, you have to create it and add this code at end file.
.yolo-main-menu .navbar-nav > li.menu-item.no-items{ display: none !important; }
Please try it, if not true, contact for me.
---------------
Best regards,
trinhnv
Attachments:
You must be logged in to view attached files.7 years, 2 months ago #2026
AnonymousTopics: 8
Posts: 14Hi
Sorry for late reply. There is no functions.php in child theme. Should I just make one?
7 years, 2 months ago #2031Hi borge77,
Thank you for feedback.
This is struct of child-theme folder (in attachment)
You must have this files, if not yet, you must create them
Attachments:
You must be logged in to view attached files.7 years, 2 months ago #2036
AnonymousTopics: 8
Posts: 14Hi. I am getting this error;
Parse error: syntax error, unexpected '">.' (T_CONSTANT_ENCAPSED_STRING) in .../wp-content/themes/yolo-canifa-child/includes/woocommerce.php on line 28
and white screen.
7 years, 2 months ago #2037
AnonymousTopics: 8
Posts: 14Sorry, never mind. I made a booboo. Problem solved
7 years, 2 months ago #2038Hi borge77,
Thanks!
-
AuthorPosts
You must be logged in and have valid license to reply to this topic.