Quantcast
Channel: Get product attribute for Simple product in WooCommerce - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Nathan for Get product attribute for Simple product in WooCommerce

$
0
0

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 IDecho '<p class="manufacturer">'.$manufacturer_name.'</p>'; // display the actual term name

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>