WooCommerce - Get custom product attribute
<p>I am trying to get a specific custom attribute in woocommerce.
I've read tons of threads on this site which offer about 3-5 methods how to do it.
After trying all, the only method that worked for me is to loop through all attributes - all others did not work.
I have a custom attribute named 'pdfs'</p>

<p><strong>The following tries did not work:</strong>   (<a href="https://stackoverflow.com/questions/13374883/woocommerce-getting-custom-attributes">link</a>)</p>

<pre><code> $global product;
 $myPdf = array_shift( wc_get_product_terms( $product-&gt;id, 'pdfs', array( 'fields' =&gt; 'names' ) ) );

 $myPdf = $product-&gt;get_attribute( 'pdfs' );

 $myPdf = get_post_meta($product-&gt;id, 'pdfs', true);
</code></pre>

<p><strong>This is the only one that did work:</strong>   (<a href="https://stackoverflow.com/questions/35089718/showing-more-product-meta-info-on-woocommerce-product-page/35667417#35667417">link</a>)</p>

<pre><code> $attributes = $product-&gt;get_attributes();
 foreach ( $attributes as $attribute ) {
    if (attribute_label( $attribute[ 'name' ] ) == "pdfs" ) {
        echo array_shift( wc_get_product_terms( $product-&gt;id,  $attribute[ 'name' ] ) );
    }
}
</code></pre>

<p>I would much rather be able to use one of the first options
Any help would be appreciated.<br>
Thanks</p>