From 48e0a25f2f431aaa3963088629ffaa746110e360 Mon Sep 17 00:00:00 2001 From: Gerhard Date: Tue, 7 May 2019 15:51:49 +0200 Subject: [PATCH] Add woocommerce_product_post_type_link_parent_category_only to only include the parent category in the slug instead of parent/child --- includes/wc-product-functions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index 89e66aef746..deb86a3e0e2 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -216,7 +216,11 @@ function wc_product_post_type_link( $permalink, $post ) { $ancestors = get_ancestors( $category_object->term_id, 'product_cat' ); foreach ( $ancestors as $ancestor ) { $ancestor_object = get_term( $ancestor, 'product_cat' ); - $product_cat = $ancestor_object->slug . '/' . $product_cat; + if ( apply_filters( 'woocommerce_product_post_type_link_parent_category_only', false ) ) { + $product_cat = $ancestor_object->slug; + } else { + $product_cat = $ancestor_object->slug . '/' . $product_cat; + } } } } else {