How WooCommerce 10.5 picks a product permalink category

WooCommerce 10.5 changes how WooCommerce product permalinks get generated, specifically the logic that picks one category when a product sits in several at once. If you have ever watched a product URL grab a broad parent category instead of the specific sub-category it belongs in, this is the fix. There are still a couple of things to watch for, though, around SEO and any legacy filters you have in place.

What changes in WooCommerce 10.5?

Until now, WooCommerce sorted every assigned category by parent ID (descending), then by term ID (ascending), and took the first one. It worked, but the result depended on the order the categories were created in the database rather than on your store’s actual hierarchy. So the URL often pointed at something less specific than the product’s real home.

From 10.5 on, WooCommerce counts the ancestors of each term and picks the deepest category in the hierarchy, so the most specific child wins. This only matters if your store uses the “Shop base with category” structure or a custom base with the %product_cat% placeholder.

The old logic and the new one

Older versions ran wp_list_sort over the term array. That is a naive approach, and it gave unpredictable permalinks unless your categories happened to be created in the right sequence.

// Legacy sorting logic (Pre-10.5)
$terms = wp_list_sort( $terms, array(
    'parent'  => 'DESC',
    'term_id' => 'ASC',
) );
$category_object = $terms[0];

The new code walks the terms and works out the depth of each one with get_ancestors. Whichever term has the most ancestors becomes the canonical choice for the URL.

// New "Deepest Category" logic (10.5+)
$deepest_term = $terms[0];
foreach ( $terms as $term ) {
    $ancestors = get_ancestors( $term->term_id, 'product_cat' );
    if ( count( $ancestors ) > count( $deepest_ancestors ) ) {
        $deepest_term = $term;
    }
}

What this means for SEO and your product permalinks

Any URL change raises the same two fears: 404s and lost rankings. WooCommerce already covers this. The wc_product_canonical_redirect() function issues a 301 from the old structure to the new one without you doing anything. Your WooCommerce product permalinks will look different in search results eventually, but live traffic does not hit a wall in the meantime.

The one place it costs you is hard-coded links in marketing emails or third-party integrations that do not follow redirects. Each of those leaves WordPress processing a 301, which shows up as a bit of extra server load. Update the links where you can. For more on handling version transitions, see my guide on the WooCommerce 10.5 variation price caching fix.

Restoring the legacy permalink behavior

Sometimes you want the old behavior back. Maybe a custom ERP integration expects the parent category in the URL, or your SEO strategy depends on it. The wc_product_post_type_link_product_cat filter gives you that: hook into it and re-apply the legacy sorting before the permalink is built.

/**
 * Restore legacy WooCommerce product permalinks category selection.
 */
function bbioon_restore_legacy_permalink_logic( $category, $terms, $post ) {
    if ( count( $terms ) <= 1 ) {
        return $category;
    }

    $sorted_terms = wp_list_sort( $terms, array(
        'parent'  => 'DESC',
        'term_id' => 'ASC',
    ) );

    return $sorted_terms[0];
}
add_filter( 'wc_product_post_type_link_product_cat', 'bbioon_restore_legacy_permalink_logic', 10, 3 );

If this WooCommerce product permalinks change is eating your dev hours, or you are worried about breaking your SEO, I can take it on. I have been wrestling with WordPress since the 4.x days and have seen every permalink disaster imaginable.

What store owners should do

For most stores this is an improvement, since the URL now matches where the product actually sits in your category tree. Before you update, check your structure under Settings > Permalinks and read GitHub PR #62321 for the technical detail. If you are on WooCommerce 10.4 already, the jump to 10.5 should be quiet, as long as you test your custom filters first.

author avatar
Ahmad Wael
I'm a WordPress and WooCommerce developer with 15+ years of experience building custom e-commerce solutions and plugins. I specialize in PHP development, following WordPress coding standards to deliver clean, maintainable code. Currently, I'm exploring AI and e-commerce by building multi-agent systems and SaaS products that integrate technologies like Google Gemini API with WordPress platforms, approaching every project with a commitment to performance, security, and exceptional user experience.