How to remove last subcategory name from woocommerce breadcrumbs?

by scotty_walker , in category: PHP CMS , a year ago

How to remove last subcategory name from woocommerce breadcrumbs?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , a year ago

@scotty_walker 

To remove the last subcategory name from WooCommerce breadcrumbs, you can use the following code snippet in your theme's functions.php file:

1
2
3
4
5
6
7
add_filter( 'woocommerce_breadcrumb_items', 'remove_last_breadcrumb_item', 10, 2 );
function remove_last_breadcrumb_item( $crumbs, $breadcrumb ) {
    if ( end( $crumbs ) == end( $breadcrumb ) ) {
        array_pop( $crumbs );
    }
    return $crumbs;
}


This code will remove the last subcategory name from the breadcrumbs displayed on your WooCommerce site. Make sure to test this code on a staging site before implementing it on your live site.

Related Threads:

How to remove name in woocommerce customer emails?
How to get woocommerce last order amount?
How to remove product-category from urls in woocommerce?
How to remove part of file name using a regex expression?
How to get current product category name in woocommerce?
How to remove woocommerce tab?