Skip to content

Instantly share code, notes, and snippets.

@Garconis
Garconis / woocommerce-cart-count-shortcode.php
Created September 27, 2017 16:32
WooCommerce | Create shortcode to display WooCommerce cart quantity and total cost — working with Ajax
<?php
// Add Shortcode [cart_count]
function get_cart_count() {
//Check if WooCommerce is active
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
$cart_contents_count = $woocommerce->cart->cart_contents_count;