Basic WooCommerce MySQL queries for Orders, Products and Categories

Rate this post

MySql DataBase

I do a lot of integration work between e-commerce cart software packages and third party systems.  Many e-commerce carts (Sunshop, VirtueMart, ZenCart, etc.) maintain their own database tables for storing orders, product, categories and everything the cart needs for the store to operate.   Accessing data from these tables is straightforward; the data is normalized for a cart application, with no meta representation of data.  Translation:  In a typical cart database, you’ll find an order table, a product table, a customer table, a product category table, etc.  It’s not difficult to extract details about what takes place in the cart.

WooCommerce has become a very popular e-commerce cart, riding on the coattails of WordPress’ great success.  I’ve implemented WooCommerce a number of times and I think it’s an excellent, light-duty cart. As a WordPress plugin, WooCommerce benefits from other, 3rd party plugins for expanding the cart’s functionality.  But what happens when you have to deal with a one-of-a-kind integration between Woo Commerce and a system for which there is no plugin solution?  We quickly find ourselves digging into the WordPress database architecture, since WooCommerce uses a blend of it’s own tables and WordPress post and taxonomy tables to store data.

Below are some basic MySQL queries for getting WooCommerce products, categories, orders, and order items from the database.  All of the queries assume the default “wp_” prefix to the database tables, so you may need to modify those prefixes if your tables are named differently.  I’ve also left some example product and order numbers in place to complete the syntax of the queries.  I’ve highlighted those values in the examples.  Change to suit your particular use.

بیشتر بخوانید:   کارهایی که باید بعد از نصب وردپرس باید انجام بدهیم

These are raw MySQL queries.  I use them in SQLyog, an excellent MySQL admin tool.  If you’re writing a PHP script for your own application needs, you can adapt these queries into your code.  Lots of example of how to do that at php.net.

Query #1: Return a list of product categories

Query #2: Get the category for a specific product

In above example, we’re getting the category for product 167; substitute your desired product ID, which you can find in the WooCommerce Products admin menu area.

Query #3: Return a list of product attributes for a specific product

In above example, we’re getting the attributes for product 167; substitute your desired product ID, which you can find in the WooCommerce Products admin menu area.

Query #4: Return a list of line item details for a specific order

In above example, we’re getting the line item details for order 7373; substitute your desired order ID, which you can find in the WooCommerce Orders admin menu area.

بیشتر بخوانید:   بهینه سازی SEO سایت بر اساس الگوریتم Rank Brain

Ref: http://zjstech.com/basic-woocommerce-mysql-queries-for-orders-products-and-categories/

Check Also

تعداد درخواست‌های http سایت با  HTTP Requests Checker 

برای بررسی  و  آنالیز سایت خودمون بهتره  ببینیم در حالت فعلی در سایت ما چند …

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *