How to change Woocommerce breadcrumbs content?

I want to customize the breadcrumbs directly from PHP. Some of the pages are generated dynamically and do not exist in the database, therefore i must automatically put them in the breadcrumbs with some sort of PHP script.

I don’t need to change default stuff, like homepage url, separators, etc…but i actually need to manually put some pages in the breadcrumbs. I was trying with some filterings and some hooks.

I’ve read the documentation but it just explains how to change default stuff.

How can i change the actual content of the breadcrumbs?

I tried this:

add_filter( 'woocommerce_breadcrumb', 'change_breadcrumb' );
function change_breadcrumb( $defaults ) {
    // Change the breadcrumb home text from 'Home' to 'Appartment'
    //do something
    return $defaults;
}

But the //do something never executes. It’s like if that filter never gets called

Solutions Collecting From Web of "How to change Woocommerce breadcrumbs content?"

That is due to the fact, that your filter woocommerce_breadcrumb doesn’t even exist.

This filter here works and pulls out all the elements, that are currently in the breadcrumb (as an array):

add_filter( 'woocommerce_get_breadcrumb', 'change_breadcrumb' );
function change_breadcrumb( $crumbs ) {
    var_dump( $crumbs );

    return $crumbs;
}

And this filter pulls out the main term (as an object).

add_filter( 'woocommerce_breadcrumb_main_term', 'change_breadcrumb' );
function change_breadcrumb( $main_term ) {
    var_dump( $main_term );

    return $main_term;
}

The ‘main term’ is just the first element that is returned by this function (reference):

$terms = wc_get_product_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent', 'order' => 'DESC' ) )

See the Action and Filter Hook Reference by woothemes for all hooks & filters.

This solution hides the category from breadcrumb and store navigation

add_filter( 'wp_get_object_terms', 'my_get_object_terms', 10, 4 );
function my_get_object_terms( $terms, $object_ids, $taxonomies, $args ) {
    $new_terms = array();

    // if a product category and on the shop page
    if (! is_admin() ) {
        foreach ( $terms as $key => $term ) {
            if ($term->slug !== 'all-products') {
                $new_terms[] = $term;
            }
        }

        $terms = $new_terms;
    }

    return $terms;
}