自定义分类WooCommerce Rest API

时间:2016-05-20 06:34:49

标签: php wordpress wordpress-plugin woocommerce woocommerce-rest-api

我目前正在使用的Wordpress应用程序正在使用WooCommerce和Tabify。

我可以通过在查询中添加filter[meta]=true将大多数字段定义为自定义字段,但有两个StatusRegion已定义为自定义分类

我一直在寻找一种方法来使用Rest API获取这些数据但到目前为止没有运气。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:2)

我最终想通了。也许这不是最实用的解决方案,每次我更新WooCommerce插件时都必须重新应用,但只需更新产品API

private function get_product_data( $product ) {
    return array(
       // your other properties go here
       'region' => wp_get_post_terms( $product->id, 'productRegion', array( 'fields' => 'names' ) ),
       'status' => wp_get_post_terms( $product->id, 'productActive', array( 'fields' => 'names' ) ),
    )
}

现在我只是从响应中访问region [0]和status [0],并做任何我需要做的事情。