diff --git a/includes/rest-api/v2/class-cocart-rest-products-v2-controller.php b/includes/rest-api/v2/class-cocart-rest-products-v2-controller.php index 2dad9c3..89d329b 100644 --- a/includes/rest-api/v2/class-cocart-rest-products-v2-controller.php +++ b/includes/rest-api/v2/class-cocart-rest-products-v2-controller.php @@ -1552,24 +1552,30 @@ protected function get_price_from_tax_display_mode( $tax_display_mode ) { * @return array Array of taxonomy terms. */ public function get_all_product_taxonomies( $taxonomy = 'cat', $page_num = '', $offset = '' ) { - $terms = array(); + $terms = get_transient( 'cocart_products_taxonomies_' . $taxonomy ); + + if ( empty( $terms ) ) { + $terms = array(); + + $all_terms = get_terms( array( + 'taxonomy' => 'product_' . $taxonomy, + 'hide_empty' => false, + 'orderby' => 'name', + 'order' => 'ASC', + 'number' => $page_num, + 'offset' => $offset, + ) ); - $all_terms = get_terms( array( - 'taxonomy' => 'product_' . $taxonomy, - 'hide_empty' => false, - 'orderby' => 'name', - 'order' => 'ASC', - 'number' => $page_num, - 'offset' => $offset, - ) ); + foreach ( $all_terms as $term ) { + $terms[] = array( + 'id' => $term->term_id, + 'name' => $term->name, + 'slug' => $term->slug, + 'rest_url' => $this->product_rest_url( $term->term_id, $taxonomy ), + ); + } - foreach ( $all_terms as $term ) { - $terms[] = array( - 'id' => $term->term_id, - 'name' => $term->name, - 'slug' => $term->slug, - 'rest_url' => $this->product_rest_url( $term->term_id, $taxonomy ), - ); + set_transient( 'cocart_products_taxonomies_' . $taxonomy, $terms, DAY_IN_SECONDS ); } return $terms;