woocommerce_product_post_type_link_parent_category_only
Filter whether to use only the top-level parent category in the product permalink.
When true, only the top-level ancestor category slug is used instead of the full category hierarchy path (e.g., 'parent' instead of 'parent/child/grandchild').
Usage
add_filter( 'woocommerce_product_post_type_link_parent_category_only', 'wp_kama_woocommerce_product_post_type_link_parent_category_only_filter' );
/**
* Function for `woocommerce_product_post_type_link_parent_category_only` filter-hook.
*
* @param bool $use_parent_only Whether to use only the top-level parent category.
*
* @return bool
*/
function wp_kama_woocommerce_product_post_type_link_parent_category_only_filter( $use_parent_only ){
// filter...
return $use_parent_only;
}
- $use_parent_only(true|false)
- Whether to use only the top-level parent category.
Default: false
Changelog
| Since 2.6.5 | Introduced. |
Where the hook is called
woocommerce_product_post_type_link_parent_category_only
woocommerce/includes/wc-product-functions.php 326
if ( apply_filters( 'woocommerce_product_post_type_link_parent_category_only', false ) ) {