title: Woocommerce Ajax add to cart programmatically
body: <p>I have this button: </p>
  
  <pre><code>&lt;a href="http://my-site/checkout/" target="_blank" class="dt-sc-button"&gt;bla bla&lt;/a&gt;
  </code></pre>
  
  <p>This button is located on my homebage and is generated by a page builder. What I want to accomplish is when somebody click on the button, it will take them on the checkout, and add a product to the cart. I know that this can be accomplished via a URL, but I need to have this button do other things as well(client idea).</p>
  
  <p>So right now I'm stucked here:</p>
  
  <p>JQuery</p>
  
  <pre><code>jQuery(document).ready(function($){     
  $(".remove-all").click(function(){
      $.ajax({
          url: "wp-admin/admin-ajax.php",
          data: 'myajax'
      });
    });
  });
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>add_action('wp_ajax_myajax', 'myajax');
  add_action('wp_ajax_nopriv_myajax', 'myajax');
  
      function myajax() {
          global $woocommerce;
          $product_id = 264;
      $woocommerce-&gt;cart-&gt;add_to_cart($product_id);
      die();
      }
  </code></pre>
  
  <p>I'm a javascript noob, so can you please point me to the right direction,  or maybe give me a hint on what I'm doing wrong.</p>
  
  <p>Thanks in advance!</p>