Ivan Crojach Karačić
Ivan Crojach Karačić

Reputation: 1911

Custom Taxonomy WooCommerce Rest API

The Wordpress application I am currently working on is using WooCommerce as well as Tabify.

Most of the fields are defined as Custom Fields which I am able to get by adding filter[meta]=true in the query but there are two Status and Region which have been defined as Custom Taxonomies.

I have been looking for a way to get these data with the Rest API but with no luck so far.

Can anyone point me in the right direction?

Upvotes: 3

Views: 2114

Answers (1)

Ivan Crojach Karačić
Ivan Crojach Karačić

Reputation: 1911

I figured it out in the end. Maybe it's not the most practical solution and it will have to be reapplied every time I update the WooCommerce plugin but just update the product API like this

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' ) ),
    )
}

Now I just access region[0] and status[0] from the response and do whatever I need to do with it.

Upvotes: 3

Related Questions