Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Woocommerce产品获取自定义属性_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 从Woocommerce产品获取自定义属性

Php 从Woocommerce产品获取自定义属性,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,当我进入产品编辑页面时,有一个选项卡“属性”。在那里我可以设置属性名及其值 我假设这就是在Woocommerce上为产品添加自定义属性的方式 但是如何在循环中得到这个值呢 我看到人们使用wc\u get\u product\u术语,但它希望我传递分类法和另一组参数。什么是分类法!?我没有手动添加它。论点是什么 $attributes = $product->get_attributes(); 这将获得产品或产品变体的属性 foreach ( $attributes as $attribu

当我进入产品编辑页面时,有一个选项卡“属性”。在那里我可以设置属性名及其值

我假设这就是在Woocommerce上为产品添加自定义属性的方式

但是如何在循环中得到这个值呢

我看到人们使用
wc\u get\u product\u术语
,但它希望我传递分类法和另一组参数。什么是分类法!?我没有手动添加它。论点是什么

$attributes = $product->get_attributes();
这将获得产品或产品变体的属性

foreach ( $attributes as $attribute ) {
    if ( $attribute['is_taxonomy'] ) {
        $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
    } 
}
$product->id
是产品id

$attribute['name']
将为您提供产品类别/分类。(您可以打印数组$attributes以查找字段名)


array('fields'=>'names')
是可选的传递参数。如果不需要,请忽略它。

我只是不明白分类学与它有什么关系。陷入同样的问题。