title: Get the selected product variation ID in WooCommerce variable products single pages
body: <p>For my Woocommerce variable products I'm implementing a custom size chooser on the single product page and have this sizes in a table:</p>
  
  <p><a href="https://i.stack.imgur.com/2NwBP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2NwBP.png" alt="enter image description here"></a></p>
  
  <p>These variations are just: <code>30B</code> <code>30C</code> <code>30D</code> rather than being split in to: <code>30</code> and <code>B</code> <code>C</code> <code>D</code></p>
  
  <p>What I am trying to figure out is: How to grab the shipping class for each product variations?</p>
  
  <p>I have something similar on cart page but I don't know what is the variation ID or how to get it from the single product page:</p>
  
  <pre><code>$product_id = ( 0 != $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
  // need the variation id for the above to be able to do the rest:
  
  $product_shipping_classes = get_the_terms( $product_id, 'product_shipping_class' );
  $product_shipping_class_name = ( $product_shipping_classes &amp;&amp; ! is_wp_error( $product_shipping_classes ) ) ? current( $product_shipping_classes )-&gt;name : '';
  </code></pre>
  
  <p>I know how to do it once I have the variation ID. I just can't figure out how to get it in order to do the rest. The only things that I need to get for it, are the product id and the slug for the variations (there is also a color attribute on this page). </p>
  
  <p>However I have given to the product a default variation to use (so the hidden <code>variation_id</code> is set). </p>
  
  <p>Perhaps that needs to be fetched first to know the id of the selected color to then fetch the variation ids for the others?</p>