Skip to content

Instantly share code, notes, and snippets.

@ronipl
Last active August 29, 2019 06:02
Show Gist options
  • Save ronipl/6b08a194b05ce50a8eaedf76e12a3052 to your computer and use it in GitHub Desktop.
Save ronipl/6b08a194b05ce50a8eaedf76e12a3052 to your computer and use it in GitHub Desktop.
woo commerce cart icon
//header.php
(function($){
$(document).ready(function(){
var cart_count = $('.cart-customlocation').text();
var cart_element = `<span>${cart_count}</span>`;
var cart_menu = $("#menu-user-menu").children('li:first-child').find('a');
$(cart_menu).find('span').remove();
$(cart_menu).append(cart_element);
});
})(jQuery);
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>" style="display:none;"><?php echo sprintf ( _n( '%d', '%d', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment