Website Building » WooCommerce » How Do You Fetch the Products of WooCommerce From Its Table in Database?

How Do You Fetch the Products of WooCommerce From Its Table in Database?

Last updated on January 20, 2023 @ 3:21 pm

WooCommerce is a popular eCommerce platform for WordPress websites. It is used by millions of online stores around the world.

WooCommerce is a free plugin that can be installed on any WordPress website.

WooCommerce stores all of its data in WordPress database tables. By default, WooCommerce creates four database tables for each installation:

PRO TIP: If you are not a developer or familiar with databases, do not attempt to fetch products from the WooCommerce database table. This can break your site and cause data loss. Only attempt this if you know what you are doing and have a backup of your site.
  • wp_woocommerce_sessions
  • wp_woocommerce_attribute_taxonomies
  • wp_woocommerce_downloadable_product_permissions
  • wp_woocommerce_order_items

In addition to these four tables, WooCommerce also creates two more tables for each installation:

  • wp_woocommerce_termmeta
  • wp_woocommerce_taxonomymeta

To fetch the products of WooCommerce from its table in the database, you can use the following SQL query:

SELECT * FROM wp_posts
WHERE post_type = ‘product’

This query will fetch all the products that are stored in the wp_posts table in the database. However, as mentioned earlier, it is important to note that directly fetching data from the WooCommerce database tables can be dangerous if you are not familiar with databases and should only be done by experienced developers with a backup of the site.

Another way to fetch products from your WooCommerce store is to use the WooCommerce REST API. The REST API allows you to access the data of your WooCommerce store, including products, orders, and customers, in a secure and structured way. This method is recommended for developers and store owners who want to fetch data from their store without directly accessing the database.

In summary, while it is possible to fetch products from the WooCommerce database table, it is not recommended unless you are an experienced developer with a backup of your site. Instead, it is recommended to use the WooCommerce REST API to access your store’s data in a secure and structured way.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.