Last active
February 25, 2019 22:58
-
-
Save michaelbourne/71f1f8e102a5b1d6e2c235a77dfdc8a9 to your computer and use it in GitHub Desktop.
Add a simple cart count to the Pro header builder cart elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add cart count and value to Cart Element text in a Pro header | |
// ============================================================================= | |
add_filter('woocommerce_add_to_cart_fragments', 'mb_cart_count_fragments', 10, 1); | |
function mb_cart_count_fragments($fragments) { | |
$count = WC()->cart->get_cart_contents_count(); | |
$fragments['.cartdropdown .x-anchor-text-primary'] = '<span class="x-anchor-text-primary">' . $count . '</span>'; | |
return $fragments; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.cartdropdown .x-anchor-text { | |
position: absolute; | |
top: -5px; | |
right: -5px; | |
background: #9ccf80; | |
border-radius: 1em; | |
width: 20px; | |
height: 20px; | |
text-align: center; | |
color: #fff; | |
line-height: 1.2; | |
z-index: 10; | |
opacity: 0; | |
pointer-events: none; | |
} | |
body.cart-has-items .cartdropdown .x-anchor-text { | |
opacity: 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment