2

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

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 output
echo '<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…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.