Quantcast
Viewing latest article 2
Browse Latest Browse All 3

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

You will use the WC_Product method get_attributes() that returns an array like:

global $product;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// Raw outputecho '<pre>'; print_r( $product_attributes ); echo '</pre>';

It should work (for real product attributes).


Now if you use some third party plugins, like product add-Ons for example, they add some custom fields to the product, but they are not product attributes…


Viewing latest article 2
Browse Latest Browse All 3

Trending Articles