Quote from lheinc on October 5, 2023, 21:59
I wanted to follow you to let you know the Permalinks Manager Pro developer provided a solution and it seems to have fixed the issue.Ā In case you are interested:
*******************his response********************************************************************
The problem here is that the HUSKY plugin uses its own algorithm to parse the product URLs that interfere with the detect functions used by my plugin. As long as Permalink Manager is deactivated, the product categories URLs are prefixed with /product-cat/, e.g.:
https://kmtj7at8uf-staging.onrocket.site/product-cat/driveway-alarms/swoof/best-use-home-use/compatibility-dakota-alert-4000-series/
HUSKY is able to detect them as product categories and modify the products' query. When PMP (Permalinks Manager Pro) is activated, this function no longer works, because the product category permalink format is changed (there is no /product-cat/ base included). To put it simply, WordPress recognizes such URLs as regular post categories, not product categories.
I cannot guarantee that this is going to work in long-term, but you can programmatically manipulate the query (check if a product category with such slug exists, and if so, replace 'category_name' with 'product_cat'):
Here is the code snippet:
https://kmtj7at8uf-staging.onrocket.site/wp-admin/admin.php?page=edit-snippet&id=42
function bis_adjust_product_cat_query( $query, $old_query, $uri_parts, $pm_query, $content_type, $element_object ) {
if ( ! empty( $query['category_name'] ) ) {
$category_slug = preg_replace( '/^([^\/]+)(.*)/', '$1', $query['category_name'] );
$category = get_term_by( 'slug', $category_slug, 'product_cat' );
if ( $category ) {
unset( $query['category_name'] );
$query['product_cat'] = $category->slug;
}
}
return $query;
}
add_filter( 'permalink_manager_filter_query', 'bis_adjust_product_cat_query', 5, 6 );
I wanted to follow you to let you know the Permalinks Manager Pro developer provided a solution and it seems to have fixed the issue.Ā In case you are interested:
*******************his response********************************************************************
The problem here is that the HUSKY plugin uses its own algorithm to parse the product URLs that interfere with the detect functions used by my plugin. As long as Permalink Manager is deactivated, the product categories URLs are prefixed with /product-cat/, e.g.:
https://kmtj7at8uf-staging.onrocket.site/product-cat/driveway-alarms/swoof/best-use-home-use/compatibility-dakota-alert-4000-series/
HUSKY is able to detect them as product categories and modify the products' query. When PMP (Permalinks Manager Pro) is activated, this function no longer works, because the product category permalink format is changed (there is no /product-cat/ base included). To put it simply, WordPress recognizes such URLs as regular post categories, not product categories.
I cannot guarantee that this is going to work in long-term, but you can programmatically manipulate the query (check if a product category with such slug exists, and if so, replace 'category_name' with 'product_cat'):
Here is the code snippet:
https://kmtj7at8uf-staging.onrocket.site/wp-admin/admin.php?page=edit-snippet&id=42
function bis_adjust_product_cat_query( $query, $old_query, $uri_parts, $pm_query, $content_type, $element_object ) {
if ( ! empty( $query['category_name'] ) ) {
$category_slug = preg_replace( '/^([^\/]+)(.*)/', '$1', $query['category_name'] );
$category = get_term_by( 'slug', $category_slug, 'product_cat' );
if ( $category ) {
unset( $query['category_name'] );
$query['product_cat'] = $category->slug;
}
}
return $query;
}
add_filter( 'permalink_manager_filter_query', 'bis_adjust_product_cat_query', 5, 6 );