title: Enable ajax on custom add-to-cart buttons in Woocommerce
body: <p>In WooCommerce, I would like to enable Ajax on my custom add to card buttons. You can check it on my website <a href="http://%20http://dev-taj-motels.pantheonsite.io/order-online/" rel="nofollow noreferrer"><strong>here</strong></a>. Any help is appreciated.</p>
  
  <p>Here is my code that create product links from a product category with a shortcode:</p>
  
  <pre><code>function woo_category_design_caa1( $atts ) {
      $category_id = $atts['category'];
  
      if(class_exists('WooCommerce')){
          $args = array(
              'post_type'             =&gt; 'product',
              'post_status'           =&gt; 'publish',
              'posts_per_page'        =&gt; -1,
              'tax_query'             =&gt; array(
                  array(
                      'taxonomy'      =&gt; 'product_cat',
                      'field'         =&gt; 'term_id', //This is optional, as it defaults to 'term_id'
                      'terms'         =&gt; $category_id,
                      'operator'      =&gt; 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                  )
              )
          );
  
          if( $term = get_term_by('id', $category_id, 'product_cat')){
              $cat_name =  $term-&gt;name;
          }
  
          $products_list = new WP_Query($args);
          if($products_list-&gt;have_posts()){
              $tableHtml = '';
              $tableHtml .= '&lt;div class="menu1"&gt;';
              $tableHtml .= "&lt;div class='heading-menu' id='a" . $category_id . "'&gt;".$cat_name."&lt;/div&gt;";
              $tableHtml .= '&lt;ul&gt;';
              while($products_list-&gt;have_posts()){
                  $products_list-&gt;the_post();
                  $_product = wc_get_product(get_the_ID());
                  if($_product-&gt;is_type( 'variable' )){
                      $args = array(
                          'post_type'     =&gt; 'product_variation',
                          'post_status'   =&gt; array( 'private', 'publish' ),
                          'numberposts'   =&gt; -1,
                          'orderby'       =&gt; 'menu_order',
                          'order'         =&gt; 'asc',
                          'post_parent'   =&gt; get_the_ID() // $post-&gt;ID
                          );
                          $variations = get_posts( $args );
                          $price ='';
                          $var_title = '';
                          $link_1 = '';
                          foreach($variations as $variation){
                              $var_title = $var_title . "/" . $variation-&gt;post_title;
                              //$price = $price . "/" . get_post_meta($variation-&gt;ID, '_regular_price', true);
                              $price = $price . '&lt;a class="btn-link-atc" href="/order-online/?add-to-cart='.get_the_ID().'&amp;variation_id='.$variation-&gt;ID.'"&gt; ' . $variation-&gt;post_title .' &amp;#x20b9; '. get_post_meta($variation-&gt;ID, '_regular_price', true) . ' &lt;/a&gt;';
                          }
                  }else{
                      $price = '&lt;a class="btn-link-atc" href="/order-online/?add-to-cart='.get_the_ID().'"&gt;Add To Cart &amp;#x20b9; '.get_post_meta(get_the_ID(), '_regular_price', true).'&lt;/a&gt;';
                      //$price = get_post_meta(get_the_ID(), '_regular_price', true);
                  }
                  $tableHtml .= '&lt;li&gt;
                  &lt;div class="title"&gt;'.get_the_title().'&lt;/div&gt;&lt;span&gt;'.$price.'&lt;/span&gt;&lt;/li&gt;';
              }
              $tableHtml .=  '&lt;/ul&gt;';
              $tableHtml .=  '&lt;/div&gt;';
  
              return $tableHtml;
              //return ' ';
          }
          else {
              return "Nothing Found.";
          }
      }
      else {
          return "Problem fetching data !";
      }
  
  
  }
  add_shortcode('woo_products_from_category_type1', 'woo_category_design_caa1');
  </code></pre>