Last active
October 18, 2021 13:37
-
-
Save diggeddy/45e91d657f15d926236be7296dc432eb to your computer and use it in GitHub Desktop.
GP Woocommerce Cart Count Shortcode
This file contains hidden or 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
function db_custom_cart_count() { | |
if ( ! class_exists( 'WooCommerce' ) ) { | |
return; | |
} | |
if ( ! isset( WC()->cart ) ) { | |
return; | |
} | |
ob_start(); | |
$no_items = ''; | |
if ( ! WC()->cart->get_cart_contents_count() > 0 ) { | |
$no_items = 'no-items'; | |
} | |
printf( | |
'<span class="cart-contents"><span class="number-of-items %1$s">%2$s</span></span>', | |
$no_items, | |
WC()->cart->get_cart_contents_count() | |
); | |
return ob_get_clean(); | |
} | |
add_shortcode('db_cart_count', 'db_custom_cart_count'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment