如何从Wordpress数据库中获取产品属性 [英] how to get product attributes from wordpress database

查看:229
本文介绍了如何从Wordpress数据库中获取产品属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写自定义代码以使用wordpress数据库创建产品详细信息页面。

Writing custom code to create product detail page with wordpress database.

我已经显示了产品标题,说明,价格,库存等,并且卡住了产品属性。
在数据库中,_product_attributes以序列化方式存储在数据库的wp_postmeta表中。而且我无法从中脱颖而出。但是我发现,每个具有其自身价格的属性值都已存储在wp_postmeta中的其他post_id中。

I have displayed product title, desc, price, stock, etc and got stuck up with product attributes. In the database, _product_attributes is stored in serialized manner in wp_postmeta table in database. And i couldn't unserailize attributes from it. But i found, each attribute value with it own price has been stored in wp_postmeta in some other post_id.

例如,具有post_id = 55的产品的属性名称大小值的值为14和18,价格为300和350,在post_id中显示为属性值和价格= 110,111

for example, product with post_id=55 has attribute name 'Size value' having values 14 and 18 and price 300 and 350, is displayed as attributes value and price in post_id=110,111


后面是否有公式?想找到该产品属性值和相应的价格值吗?

is there any formula behind? Any idea to find this product attribute value and corresponding price value?

推荐答案

产品属性存储在两个位置-wp_terms,wp_term_taxonomy和wp_term_relationships(这是第一位-每个属性的分类名称都以pa_开头-例如,如果您具有color属性,则在pa_color下),然后作为wp_postmeta中的PHP序列化数组,位于'_product_attributes'meta_key下。

Product attributes are stored in two locations - in wp_terms, wp_term_taxonomy and wp_term_relationships (that's the first place - each attribute is preceded by pa_ for its taxonomy name - e.g. if you have a color attribute, it's under pa_color) then also as a PHP serialized array in wp_postmeta under '_product_attributes' meta_key.

您可以在此处找到构造序列化属性数组的方法:

You can find the method to construct the seriliazed attributes array here:

https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-ajax .php

查找函数save_attributes()和add_attribute以查看序列化数组的构造方式。

Look for function save_attributes() and add_attribute to see how the serialized array is constructed.

更新:更高版本的wooCommerce在wp_optio中也有序列化的数组ns在_transient_wc_attribute_taxonomies键和一个名为wp_woocommerce_attribute_taxonomies的新表下。

Update: Later versions of wooCommerce also have a serialized array in wp_options under the _transient_wc_attribute_taxonomies key and a new table called wp_woocommerce_attribute_taxonomies.

这篇关于如何从Wordpress数据库中获取产品属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆