Whenever I install any new plugin I have a great curiosity as to how they are storing data in the database, so I take a look at core files and study them. I've been playing with WooCommerce for a long time and have gone through its table numerous times but didn't think that there were developers/users who were looking for such kind of tutorial. So I decided to put my Product Attribute knowledge into a single piece today.
A product attribute is a characteristic that defines a particular product and will affect a consumer's purchase decision. WooCommerce uses the WordPress default tables to store the entire product attribute.
Let's take an example, of Woo Product Happy Ninja
In the above product, there are 2 attributes namely Size and Color now let see how it is stored and from where they are fetched.
The entire attribute category is stored in this table with a prefix.
pa_ For example, if we add Color then it will be stored as:
The entire attribute's value is stored in this table with their name and slug. So for example, if we have Black, Blue, Seal Brown colors then it will be stored as:
It stores the mapping of the post/product ID with the term ID, So, for example, the above product Happy Ninja has attribute color with values Blue and White then it will be stored as:
WooCommerce also keep all the assigned attribute name as a serialized way in postmeta table under
meta_key => _product_attributes, like this:
So in the frontend or single product field, attribute names are displayed from
_product_attributes meta_key and the values are displayed from
wp_terms.name, (obviously with relational data).
The relations table will look like this:
Hope you all enjoyed this article and if you have any queries then let me know through comments so that I can reply one by one.
If you need extensive guidance on how to manage product categories, tags, and attributes, please refer to the official WooCommerce documentation. Additionally, if you wish to gain a deeper understanding of the database structure of WooCommerce, we recommend checking out our article "Decoding Product Data: Part 1 of the WooCommerce DB Series."