I need to get product attributes from product in WooCommerce, type product Simple product, some product can be as dropdown, but much options as radio button.
How I can do this? How it possible?
With variations I have no problem, but for simple I can’t get them.
2 Answers
Building on Loic’s answer for an attribute of pa_manufacturer
:
if ( get_post_type( $post ) === 'product' && ! is_a($product, 'WC_Product') ) {
$product = wc_get_product( get_the_id() ); // Get the WC_Product Object
}
$product_attributes = $product->get_attributes(); // Get the product attributes
// Output
$manufacturer_id = $product_attributes['pa_manufacturer']['options']['0']; // returns the ID of the term
$manufacturer_name = get_term( $manufacturer_id )->name; // gets the term name of the term from the ID
echo '<p class="manufacturer">'.$manufacturer_name.'</p>'; // display the actual term name