title: Woocommerce get product sku for single product page in functions.php
body: <p>I'm having a lot of trouble getting the product SKU for a product in a single product page inside of functions.php.  I have multiple single product pages and I want different text to display depending on the product.  I've created a child theme and I'm working in the functions.php file.  I'm new to wordpress and editing themes so I don't quite understand the order of operations yet.  I was able to get code working to loop through and give me all the SKU's for all the products but that's independent of the actual page that I'm on.</p>
  
  <p>I've tried a bunch of things.  The common solution seems to be:</p>
  
  <pre><code>global $product;
  echo $product-&gt;get_sku(); 
  </code></pre>
  
  <p>but that doesn't work.  For some reason the $product variable is null inside the functions.php script.  </p>
  
  <p>The loop that I have loops through all the product posts and gets the post ID.  I also tried getting the ID of the current page but was also unsuccessful in doing that (the code below was copied from another site).  Any help would be greatly appreciated.  Thanks.</p>
  
  <pre><code>$full_product_list = array();
      $loop = new WP_Query( array( 'post_type' =&gt; array('product', 'product_variation'), 'posts_per_page' =&gt; -1 ) );
  
      while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
          $theid = get_the_ID();
          $product = new WC_Product($theid);
  </code></pre>