Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Update WooCommerce mini cart count via AJAX
add_action('wp_ajax_cart_count', 'custom_cart_count');
add_action('wp_ajax_nopriv_cart_count', 'custom_cart_count');
function custom_cart_count() {
echo WC()->cart->cart_contents_count;
add_action('wp_enqueue_scripts', 'custom_scripts');
function custom_scripts()
wc_enqueue_js( "
url: '".admin_url('admin-ajax.php')."',
data: {
'action': 'cart_count'
success: function(resp) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment