Hi @webartist00,
Top-level information for WooCommerce products is stored primarily in the wp_posts table in the WordPress database. The post_type for a product is ‘product’ or ‘product_variation’.
SELECT * FROM
wp_posts
WHERE post_type
= 'product'
Product data is also stored in a few other tables and you can learn more about it here.
To retrieve a product image:
You will first need to get the post_id for the product from the wp_posts table using the above query. Now, use the post_id to get the meta value for the _thumbnail_id meta key.
SELECT * FROM
wp_postmeta
WHERE post_id
= '<post_id for product from wp_posts>'
You then use the _thumbnail_id value to get the attached product image info:
SELECT * FROM
wp_postmeta
WHERE meta_key
= '_wp_attached_file' and post_id
= '<_thumbnail_id meta value>'
I hope this helps!
Hi @webartist00
I can see @kaavyaiyer Already explained you in detail. Furthermore, you can read this article on how WooCommerce database schema work.
Thanks!
Hi @webartist00,
I just wanted to clarify a couple of things.
It is not recommended to execute queries directly through the code. WooCommerce already provides a list of methods that can be used to retrieve product information. You can read more about here.
For custom queries, you should make use of the wpdb class.
If you can let me know what your use-case is, I can provide you with specific suggestions to go about it.
I hope this helps!