Skip to content

Instantly share code, notes, and snippets.

@jasalt
Created May 25, 2021 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasalt/f6a8e6b3d9ad7df94387ee5edb4e5225 to your computer and use it in GitHub Desktop.
Save jasalt/f6a8e6b3d9ad7df94387ee5edb4e5225 to your computer and use it in GitHub Desktop.
Add product category urls to WooCommerce REST API v3
/* Adds category term links to /products/categories endpoint giving full urls / permalinks to the category archive pages. */
add_filter('woocommerce_rest_prepare_product_cat', 'rest_add_cat_url', 10, 3);
function rest_add_cat_url($response, $object, $request) {
if (empty($response->data)){ return $response; }
$response->data['term_link'] = get_term_link($object->term_id);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment