WooCommerce: Show Cart Total Ajax

Posted on - 02-07-210 Comments

WooCommerce can be modified in many different ways. Using oxygen builder you can get the most out of your WooCommerce and modify it to its core. The below steps show how to make your WooCommerce cart total in a ajax format. You can use the element literally anywhere for your needs.

  1. Add a codeblock
  2. Insert the follwing into "PHP & HTML":
<div class="cart-count">
   <?php echo WC()->cart->get_cart_contents_count();?>
 </div>
  1. Install you favourite code snippets plugin like - Advanced Scripts
  2. Create a New PHP Snippet / PHP Script
  3. Insert the following into the "Code"-section:
Code of WooCommerce Cart Total Ajax in Advanced Scripts
 add_filter('woocommerce_add_to_cart_fragments', function($fragments) {
 	ob_start();
 ?>

 <div class="cart-count">
 	<?php echo WC()->cart->get_cart_contents_count(); ?>
 </div>

 <?php $fragments['div.cart-count'] = ob_get_clean();
 return $fragments;
 });
  1. Now you can give you snippet a name and save it.

Leave a Reply

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram