Add woocommerce_product_post_type_link_parent_category_only to only include the parent category in the slug instead of parent/child

This commit is contained in:
Gerhard 2019-05-07 15:51:49 +02:00
parent be737d6f9e
commit 48e0a25f2f
1 changed files with 5 additions and 1 deletions

View File

@ -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 {