title: WooCommerce: Get SKUs of all product variations
body: <p>I have a list of products which should show variations in it's own row.
  The code for that works fine so far.</p>
  
  <p>But I couldn't figure out how I could show the SKU of a variation.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>$args = [
      'status'    =&gt; array('publish', 'draft'),
      'orderby'   =&gt; 'name',
      'order'     =&gt; 'ASC',
      'limit'     =&gt; -1,
  ];
  $vendor_products = wc_get_products($args);
  
  $list_array = array();
  
  foreach ($vendor_products as $key =&gt; $product) {
  
      if ($product-&gt;get_type() == "variable") {
  
          foreach ($product-&gt;get_variation_attributes() as $variations) {
              foreach ($variations as $variation) {
  
                  $list_array[] = array(
                      'SKU'      =&gt; $product-&gt;get_sku(),
                      'Name'     =&gt; $product-&gt;get_title() . " - " . $variation,
                  );
  
              }
          }
  
      } else {
  
          $list_array[] = array(
              'SKU'      =&gt; $product-&gt;get_sku(),
              'Name'     =&gt; $product-&gt;get_title(),
          );
  
  
      }
  }
  
  return $list_array;
  </code></pre>
  
  <p>I tried to display the product attributes and I also tried to get the ID of the variation.
  Nothing works for me?!</p>
  
  <p>Is there no simple way to get the variation SKU?</p>