Whenever I install any new plugin I have a great curiosity as for how they are storing data in the database, so I take a look in core files and study them. I’m playing with WooCommerce from a long time and gone through its table for the numerous number of time but didn’t think that there are developer/users who are looking for such kind of tutorial. So today I decided to put my Product Attribute knowledge into a single piece.
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 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 color 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 singles product field, attributes 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 query then let me know through comments so that I can reply one by one.