Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 867
Ivan Crojach Karačić Avatar asked Feb 16 '26 20:02

Ivan Crojach Karačić


1 Answers

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.

like image 55
Ivan Crojach Karačić Avatar answered Feb 20 '26 06:02

Ivan Crojach Karačić



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!