title: How to add to cart without reloading page on woocommerce?
body: <p>I'm building a website and I want to show the options of the products with variations on the main and shop page.</p>
  
  <p>I use this code to acomplished that:</p>
  
  <pre><code>/**
   * Replace add to cart button in the loop.
   */
  function iconic_change_loop_add_to_cart() {
      remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
      add_action( 'woocommerce_after_shop_loop_item', 'iconic_template_loop_add_to_cart', 10 );
  }
  
  add_action( 'init', 'iconic_change_loop_add_to_cart', 10 );
  
  /**
   * Use single add to cart button for variable products.
   */
  function iconic_template_loop_add_to_cart() {
      global $product;
  
      if ( ! $product-&gt;is_type( 'variable' ) ) {
          woocommerce_template_loop_add_to_cart();
      return;
      }
  
  remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
      add_action( 'woocommerce_single_variation', 'iconic_loop_variation_add_to_cart_button', 20 );
  
      woocommerce_template_single_add_to_cart();
  }
  
  /**
   * Customise variable add to cart button for loop.
   *
   * Remove qty selector and simplify.
   */
  function iconic_loop_variation_add_to_cart_button() {
      global $product;
  
      ?&gt;
      &lt;div class="woocommerce-variation-add-to-cart variations_button"&gt;
          &lt;button type="submit" class="single_add_to_cart_button button"&gt;&lt;?php echo esc_html( $product-&gt;single_add_to_cart_text() ); ?&gt;&lt;/button&gt;
          &lt;input type="hidden" name="add-to-cart" value="&lt;?php echo absint( $product-&gt;get_id() ); ?&gt;" /&gt;
          &lt;input type="hidden" name="product_id" value="&lt;?php echo absint( $product-&gt;get_id() ); ?&gt;" /&gt;
          &lt;input type="hidden" name="variation_id" class="variation_id" value="0" /&gt;
      &lt;/div&gt;
      &lt;?php
  }
  </code></pre>
  
  <p>And works great, but if you add a product to the cart, also sends you to the page of that product. So I add this code, so the page just reloads.</p>
  
  <pre><code>function iconic_add_to_cart_form_action( $redirect ) {
      if ( ! is_archive() ) {
          return $redirect;
      }
  
      return '';
  }
  add_filter( 'woocommerce_add_to_cart_form_action', 'iconic_add_to_cart_form_action' );
  </code></pre>
  
  <p>Can someone help me? I want to add the product withou reloading or sending the clientes to another page.</p>
  
  <p>Thanks!! </p>