title: WooCommerce - Custom cart - How to add AJAX function?
body: <p>I coded my own mini-shopping-cart for a website I'm currently working on and it's working fine. Now I need a way to add AJAX to said cart.
  Here's the code so far:</p>
  
  <pre><code>&lt;div class="custom-cart-container"&gt;
      &lt;div class="shopping_cart_link"&gt;
          &lt;a class="shopping_cart_link_text" href="http://www.wein-partner.at/wp/cart/"&gt;&lt;span class="fa"&gt;&amp;#xf07a;&lt;/span&gt; ZUM &lt;span class="fat"&gt; WARENKORB&lt;/span&gt;&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="shopping_cart_custom"&gt;
          &lt;div class="cart_custom_top"&gt;
              &lt;a class="cart_preview fa dropdown-toggle" href="#" data-toggle="dropdown"&gt; &amp;#xf07a;  &amp;#xf06e;  &lt;a class="sub dropdown-toggle" href="#" data-toggle="dropdown"&gt; Schnellansicht&lt;/a&gt;&lt;/a&gt;
              &lt;div class="dropdown"&gt;
                  &lt;?php woocommerce_mini_cart(); ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="cart_custom_bottom"&gt;
          &lt;?php
              global $woocommerce;
  
              // get cart quantity
              $qty = $woocommerce-&gt;cart-&gt;get_cart_contents_count();
  
              // get cart total
              $total = $woocommerce-&gt;cart-&gt;get_cart_total();
  
              // get cart url
              $cart_url = $woocommerce-&gt;cart-&gt;get_cart_url();
  
              // if multiple products in cart
              if($qty&gt;1)
                  echo '&lt;a href="'.$cart_url.'"&gt;'.$qty.' Produkte - '.$total.'&lt;/a&gt;';
  
  
              // if single product in cart
              if($qty==1)
                  echo '&lt;a href="'.$cart_url.'"&gt;1 Produkt - '.$total.'&lt;/a&gt;';
          ?&gt;  
          &lt;/div&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>To repeat my headline: <strong>How do I add AJAX-functionality to that cart?</strong></p>
  
  <p>I already have an add-to-cart.js file that runs with every loop.</p>
  
  <p><strong>edit01:</strong>
  Here's the add-to-cart.php as well:</p>
  
  <pre><code>if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?&gt;
  &lt;?php
  global $product;
  
  echo apply_filters( 'woocommerce_loop_add_to_cart_link',
      sprintf( '&lt;a href="%s" rel="nofollow" data-quantity="1" data-product_id="%s" data-product_sku="%s" class="button btn btn-default btn-theme-default btn-cart %s product_type_%s"&gt;%s&lt;/a&gt;',
          esc_url( $product-&gt;add_to_cart_url() ),
          esc_attr( $product-&gt;id ),
          esc_attr( $product-&gt;get_sku() ),
          $product-&gt;is_purchasable() &amp;&amp; $product-&gt;is_in_stock() ? 'add_to_cart_button' : '',
          esc_attr( $product-&gt;product_type ),
          esc_html( $product-&gt;add_to_cart_text() )
      ),
  $product );
  </code></pre>