Skip to content

Instantly share code, notes, and snippets.

@chetansatasiya
Created March 13, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetansatasiya/15460a2e9fc6af10d74afd7138005dd1 to your computer and use it in GitHub Desktop.
Save chetansatasiya/15460a2e9fc6af10d74afd7138005dd1 to your computer and use it in GitHub Desktop.
Woo Menu Cart
<?php
function cs_wcmenucart($menu, $args) {
global $woocommerce;
$viewing_cart = __('View your shopping cart', 'your-theme-slug');
$start_shopping = __('Start shopping', 'your-theme-slug');
$cart_url = $woocommerce->cart->get_cart_url();
$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
$cart_contents_count = $woocommerce->cart->cart_contents_count;
$cart_contents = sprintf(_n('%d', '%d', $cart_contents_count, 'your-theme-slug'), $cart_contents_count);
$cart_total = $woocommerce->cart->get_cart_total();
// Uncomment the line below to hide nav menu cart item when there are no items in the cart
// if ( $cart_contents_count > 0 ) {
if ($cart_contents_count == 0) {
$menu_item = '<li class="right"><a class="wcmenucart-contents" href="'. $shop_page_url .'" title="'. $start_shopping .'">';
} else {
$menu_item = '<li class="right"><a class="wcmenucart-contents" href="'. $cart_url .'" title="'. $viewing_cart .'">';
}
$menu_item .= '<i class="fa fa-shopping-cart"></i> ';
$menu_item .= '<span style="top: -2px;float: right;font-size: 13px;font-family: \'open sans\';">'.$cart_contents.'</span>';
$menu_item .= '</a></li>';
// Uncomment the line below to hide nav menu cart item when there are no items in the cart
// }
return $menu_item;
}
// display the icon
echo cs_wcmenucart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment