Created
May 25, 2021 12:22
-
-
Save jasalt/f6a8e6b3d9ad7df94387ee5edb4e5225 to your computer and use it in GitHub Desktop.
Add product category urls to WooCommerce REST API v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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