title: Adding Product Variations to product page
body: <p>I am working on <a href="http://fitboxmeals.com/order/" rel="nofollow">http://fitboxmeals.com/order/</a> and I would like to use this snippet of code in my woocommerce theme's function.php so my product variations show up on the meals products page.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>if ( ! function_exists( ‘woocommerce_template_loop_add_to_cart’ ) ) { function woocommerce_template_loop_add_to_cart() { global $product; if ($product-&gt;product_type == "variable") { woocommerce_variable_add_to_cart(); } else { woocommerce_get_template(
  'loop/add-to-cart.php' ); } } }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The code works but now when I add a product to the cart, I would like to reset the variations so the user can select those variations again for the same product or a different one after a product has been added to the cart.  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $woocommerce, $product, $post; ?&gt;
  
  &lt;?php do_action( 'woocommerce_before_add_to_cart_form' ); ?&gt;
  
  &lt;form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="&lt;?php echo $post-&gt;ID; ?&gt;" data-product_variations="&lt;?php echo esc_attr( json_encode( $available_variations ) ) ?&gt;"&gt;
    &lt;?php if ( ! empty( $available_variations ) ) : ?&gt;
    &lt;table class="variations" cellspacing="0"&gt;
      &lt;tbody&gt;
        &lt;?php $loop=0 ; foreach ( $attributes as $name=&gt;$options ) : $loop++; ?&gt;
        &lt;tr&gt;
          &lt;td class="label"&gt;
            &lt;label for="&lt;?php echo sanitize_title($name); ?&gt;"&gt;
              &lt;?php echo wc_attribute_label( $name ); ?&gt;
            &lt;/label&gt;
          &lt;/td&gt;
          &lt;td class="value"&gt;
            &lt;select id="&lt;?php echo esc_attr( sanitize_title( $name ) ); ?&gt;" name="attribute_&lt;?php echo sanitize_title( $name ); ?&gt;"&gt;
              &lt;option value=""&gt;
                &lt;?php echo __( 'Choose an option', ETHEME_DOMAIN ) ?&gt;&amp;hellip;&lt;/option&gt;
              &lt;?php if ( is_array( $options ) ) { if ( isset( $_REQUEST[ 'attribute_' . sanitize_title( $name ) ] ) ) { $selected_value=$ _REQUEST[ 'attribute_' . sanitize_title( $name ) ]; } elseif ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) { $selected_value=$
              selected_attributes[ sanitize_title( $name ) ]; } else { $selected_value='' ; } // Get terms if this is a taxonomy - ordered if ( taxonomy_exists( $name ) ) { $orderby=w c_attribute_orderby( $name ); switch ( $orderby ) { case 'name' : $args=a
              rray( 'orderby'=&gt;'name', 'hide_empty' =&gt; false, 'menu_order' =&gt; false ); break; case 'id' : $args = array( 'orderby' =&gt; 'id', 'order' =&gt; 'ASC', 'menu_order' =&gt; false, 'hide_empty' =&gt; false ); break; case 'menu_order' : $args = array( 'menu_order' =&gt; 'ASC',
              'hide_empty' =&gt; false ); break; } $terms = get_terms( $name, $args ); foreach ( $terms as $term ) { if ( ! in_array( $term-&gt;slug, $options ) ) continue; echo '
              &lt;option value="' . esc_attr( $term-&gt;slug ) . '"
              ' . selected( sanitize_title( $selected_value ), sanitize_title( $term-&gt;slug ), false ) . '&gt;' . apply_filters( 'woocommerce_variation_option_name', $term-&gt;name ) . '&lt;/option&gt;'; } } else { foreach ( $options as $option ) { echo '
              &lt;option value="' . esc_attr( sanitize_title( $option ) ) . '"
              ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '&gt;' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '&lt;/option&gt;'; } } } ?&gt;
            &lt;/select&gt;
            &lt;?php if ( sizeof($attributes)==$ loop ) echo '&lt;a class="reset_variations" href="#reset"&gt;' . __( 'Clear selection', ETHEME_DOMAIN ) . '&lt;/a&gt;'; ?&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;?php endforeach;?&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  
    &lt;?php do_action( 'woocommerce_before_add_to_cart_button' ); ?&gt;
  
    &lt;div class="single_variation_wrap" style="display:none;"&gt;
      &lt;?php do_action( 'woocommerce_before_single_variation' ); ?&gt;
  
      &lt;div class="single_variation"&gt;&lt;/div&gt;
  
      &lt;div class="variations_button"&gt;
        &lt;?php woocommerce_quantity_input(); ?&gt;
        &lt;button type="submit" class="single_add_to_cart_button button big active alt"&gt;&lt;span&gt;&lt;?php echo $product-&gt;single_add_to_cart_text(); ?&gt;&lt;/span&gt;
        &lt;/button&gt;
      &lt;/div&gt;
  
      &lt;input type="hidden" name="add-to-cart" value="&lt;?php echo $product-&gt;id; ?&gt;" /&gt;
      &lt;input type="hidden" name="product_id" value="&lt;?php echo esc_attr( $post-&gt;ID ); ?&gt;" /&gt;
      &lt;input type="hidden" name="variation_id" value="" /&gt;
  
      &lt;?php do_action( 'woocommerce_after_single_variation' ); ?&gt;
    &lt;/div&gt;
  
    &lt;?php do_action( 'woocommerce_after_add_to_cart_button' ); ?&gt;
  
    &lt;?php else : ?&gt;
  
    &lt;p class="stock out-of-stock"&gt;
      &lt;?php _e( 'This product is currently out of stock and unavailable.', ETHEME_DOMAIN ); ?&gt;
    &lt;/p&gt;
  
    &lt;?php endif; ?&gt;
  
  &lt;/form&gt;
  
  &lt;?php do_action( 'woocommerce_after_add_to_cart_form' ); ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I hope this helps, any suggestions would be greatly appreciated. </p>