Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Last active October 18, 2021 13:37
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 diggeddy/45e91d657f15d926236be7296dc432eb to your computer and use it in GitHub Desktop.
Save diggeddy/45e91d657f15d926236be7296dc432eb to your computer and use it in GitHub Desktop.
GP Woocommerce Cart Count Shortcode
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