By Lerry


2019-04-12 15:12:17 8 Comments

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.

1 comments

@LoicTheAztec 2019-04-12 15:17:39

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…

Related Questions

Sponsored Content

1 Answered Questions

How to add checkboxes for a woocommerce product?

1 Answered Questions

[SOLVED] Menu not show woocommerce product category

  • 2016-10-26 19:24:41
  • bradley546994
  • 1982 View
  • 3 Score
  • 1 Answer
  • Tags:   woocommerce

1 Answered Questions

[SOLVED] How to assign specific attribute to variation for woocommerce product?

  • 2017-02-26 22:41:34
  • Donatas
  • 1187 View
  • 2 Score
  • 1 Answer
  • Tags:   woocommerce

0 Answered Questions

Get product variation attribute titles - WooCommerce

1 Answered Questions

[SOLVED] WooCommerce Change Product Global Attribute Value via CRUD for Simple Product

  • 2018-05-16 00:25:17
  • Daniel Klose
  • 656 View
  • 1 Score
  • 1 Answer
  • Tags:   woocommerce

0 Answered Questions

WooCommerce Product Bundles

  • 2018-05-02 13:23:06
  • Alexaidzuo
  • 290 View
  • 0 Score
  • 0 Answer
  • Tags:   php woocommerce

0 Answered Questions

Add attribute / custom attribute to product in woocommerce

1 Answered Questions

[SOLVED] Creating custom Woocommerce attribute taxonomies from a plugin

1 Answered Questions

[SOLVED] Woocommerce - Display active variation product price

1 Answered Questions

[SOLVED] WordPress Woocommerce - Product Type

  • 2014-11-19 09:30:09
  • Kobus Beets
  • 3701 View
  • 1 Score
  • 1 Answer
  • Tags:   php woocommerce

Sponsored Content