Hello there,
I hope you’re doing well :D.
Could you try to add the following code in the functions.php of your active theme
if( ! function_exists( 'yith_wcan_set_query_vars' ) ){
function yith_wcan_set_query_vars(){
if ( ! function_exists( 'YITH_WCAN_Query' ) ) {
return;
}
$qo = get_queried_object();
$query_vars = YITH_WCAN_Query()->get_query_vars();
if ( is_product_taxonomy() && $qo instanceof WP_Term && ! isset( $query_vars[ $qo->taxonomy ] ) ) {
YITH_WCAN_Query()->set( $qo->taxonomy, $qo->slug );
} elseif ( is_page() && $qo instanceof WP_Post && ! isset( $query_vars['product_cat'] ) ) {
$page_slug = $qo->post_name;
$related_term = get_term_by( 'slug', $page_slug, 'product_cat' );
if ( $related_term && ! is_wp_error( $related_term ) ) {
YITH_WCAN_Query()->set( 'product_cat', $related_term->slug );
}
}
}
add_action( 'wp', 'yith_wcan_set_query_vars' );
}
It should retrieve the current category and should work for custom pages.
Please, try it and let me know.
Have a good day.