Last active
August 24, 2018 21:55
-
-
Save michaelbourne/27b2a07ec3452c8f6ec79044d57f0219 to your computer and use it in GitHub Desktop.
Add the Woocommerce cart count and cart total to a cart element in the Pro header builder.
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(); | |
$value = ($count == 0) ? '$0.00' : WC()->cart->get_cart_total(); | |
$cart = ($count == 0) ? 'Cart' : 'Items: ' . $count; | |
$fragments['.cartdropdown .x-anchor-text-secondary'] = '<span class="x-anchor-text-secondary">' . $value . '</span>'; | |
$fragments['.cartdropdown .x-anchor-text-primary'] = '<span class="x-anchor-text-primary">' . $cart . '</span>'; | |
return $fragments; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment