MySQL WooCommerce:在数据库中查找产品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36965352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WooCommerce: Finding the products in database
提问by T.Doe
I'm creating a website using WooCommerce and I want to restrict the available products to users depending on the postcode that they enter in the search form on my home page.
我正在使用 WooCommerce 创建一个网站,我想根据用户在我主页上的搜索表单中输入的邮政编码将可用产品限制为用户。
To be able to achieve that I'll have to specify the conditions of each product within the database in phpMyAdmin, but I can't seem to find it.
为了能够实现这一点,我必须在 phpMyAdmin 的数据库中指定每个产品的条件,但我似乎找不到它。
Does anybody know where the woocommerce database for products and/or categories are within phpmyAdmin?
有人知道 phpmyAdmin 中产品和/或类别的 woocommerce 数据库在哪里吗?
Thank you in advance.
先感谢您。
回答by LoicTheAztec
Products are located mainly in 2 tables:
产品主要位于 2 个表中:
wp_posts
table with apost_type
likeproduct
orproduct_variation
,wp_postmeta
table with the correspondingpost_id
by product (the product ID).
wp_posts
带有post_type
喜欢product
或的表product_variation
,wp_postmeta
带有相应post_id
按产品(产品 ID)的表格。
Product types, categories, subcategories, tags, attributes and all other custom taxonomies are located in the following tables:
产品类型、类别、子类别、标签、属性和所有其他自定义分类法位于下表中:
wp_terms
wp_termmeta
wp_term_taxonomy
wp_term_relationships
wp_woocommerce_termmeta
wp_woocommerce_attribute_taxonomies
(for product attributes only)
wp_terms
wp_termmeta
wp_term_taxonomy
wp_term_relationships
wp_woocommerce_termmeta
wp_woocommerce_attribute_taxonomies
(仅适用于产品属性)
Product typesare handled by custom taxonomy product_type
with the following default terms:
产品类型由product_type
具有以下默认术语的自定义分类法处理:
simple
grouped
variable
external
simple
grouped
variable
external
Since Woocommerce 3+ a new custom taxonomy named product_visibility
handle:
由于 Woocommerce 3+ 一个名为product_visibility
handle的新自定义分类法:
- The product visibility with the terms
exclude-from-search
andexclude-from-catalog
- The feature products with the term
featured
- The stock status with the term
outofstock
- The rating system with terms from
rated-1
torated-5
- 具有条款
exclude-from-search
和条件的产品可见性exclude-from-catalog
- 带有术语的特色产品
featured
- 有期限的库存状态
outofstock
- 具有从
rated-1
到的术语的评级系统rated-5
Particular feature: Each product attributeis a custom taxonomy…
特殊功能:每个产品属性都是自定义分类法……
References:
参考:
- Normal tables: Wordpress database description
- Specific tables: Woocommerce database description
- 普通表:Wordpress 数据库说明
- 具体表格:Woocommerce 数据库说明
回答by Swapnali
The following tables are store WooCommerce products database :
下表是存储 WooCommerce 产品数据库:
wp_posts-
The core of the WordPress data is the posts. It is stored a
post_type
like product orvariable_product
.wp_postmeta-
Each post features information called the meta data and it is stored in the wp_postmeta. Some plugins may add their own information to this table like WooCommerce plugin store
product_id
of product in wp_postmeta table.
wp_posts-
WordPress 数据的核心是帖子。它存储为
post_type
类似产品或variable_product
.wp_postmeta-
每个帖子都有称为元数据的信息,它存储在 wp_postmeta.xml 文件中。某些插件可能会将自己的信息添加到此表中,例如
product_id
wp_postmeta 表中产品的WooCommerce 插件商店。
Product categories, subcategories stored in this table :
此表中存储的产品类别、子类别:
- wp_terms
- wp_termmeta
- wp_term_taxonomy
- wp_term_relationships
- wp_woocommerce_termmeta
- wp_terms
- wp_termmeta
- wp_term_taxonomy
- wp_term_relationships
- wp_woocommerce_termmeta
following QueryReturn a list of product categories
以下查询返回产品类别列表
SELECT wp_terms.*
FROM wp_terms
LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
WHERE wp_term_taxonomy.taxonomy = 'product_cat';
for more reference -
更多参考 -
回答by bsun1991
Bulk add new categories to Woo:
向 Woo 批量添加新类别:
Insert category id, name, url key
插入类别 id、名称、url 键
INSERT INTO wp_terms
VALUES
(57, 'Apples', 'fruit-apples', '0'),
(58, 'Bananas', 'fruit-bananas', '0');
Set the term values as catergories
将术语值设置为类别
INSERT INTO wp_term_taxonomy
VALUES
(57, 57, 'product_cat', '', 17, 0),
(58, 58, 'product_cat', '', 17, 0)
17 - is parent category, if there is one
17 - 是父类别,如果有的话
key here is to make sure the wp_term_taxonomy table term_taxonomy_id, term_id are equal to wp_term table's term_id
这里的关键是确保 wp_term_taxonomy 表 term_taxonomy_id, term_id 等于 wp_term 表的 term_id
After doing the steps above go to wordpress admin and save any existing category. This will update the DB to include your bulk added categories
完成上述步骤后,转到 wordpress admin 并保存任何现有类别。这将更新数据库以包含您批量添加的类别
回答by Pranav
I would recommend using WordPress custom fieldsto store eligible postcodes for each product. add_post_meta()and update_post_metaare what you're looking for. It's not recommended to alter the default WordPress table structure. All postmetas are inserted in wp_postmeta
table. You can find the corresponding products within wp_posts
table.
我建议使用WordPress 自定义字段来存储每个产品的合格邮政编码。add_post_meta()和update_post_meta就是你要找的。不建议更改默认的 WordPress 表结构。所有 postmetas 都插入到wp_postmeta
表中。您可以在wp_posts
表格中找到相应的产品。