I have found where in WooCommerce (WC) I can edit directly to get my desired result, which is editing the following function: https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-breadcrumb.php#L222
private function add_crumbs_product_tag() {
$current_term = $GLOBALS['wp_query']->get_queried_object();
$this->prepend_shop_page();
/* translators: %s: product tag */
$this->add_crumb( sprintf( __( 'My Edit: %s', 'woocommerce' ), $current_term->name ), get_term_link( $current_term, 'product_tag' ) );
}
Now I know that it is bad practice to directly edit the WC plugin, so I am looking for an alternative, so that when WC updates, the changes aren't overwritten.
Override Attempt
I have tried to add my edited class to my child theme (mytheme-child/woocommerce/includes/class-wc-breadcrumb.php) but this doesn't seem to work.
What can I do?
Try the following instead using the specific woocommerce_get_breadcrumb
filter hook:
add_filter( 'woocommerce_get_breadcrumb', 'custom_product_tag_crumb', 20, 2 );
function custom_product_tag_crumb( $crumbs, $breadcrumb ){
// Targetting product tags
$current_taxonomy = 'product_tag';
$current_term = $GLOBALS['wp_query']->get_queried_object();
$current_key_index = sizeof($crumbs) - 1;
// Only product tags
if( is_a($current_term, 'WP_Term') && term_exists( $current_term->term_id, $current_taxonomy ) ) {
// The label term name
$crumbs[$current_key_index][0] = sprintf( __( 'My Edit: %s', 'woocommerce' ), $current_term->name );
// The term link (not really necessary as we are already on the page)
$crumbs[$current_key_index][1] = get_term_link( $current_term, $current_taxonomy );
}
return $crumbs;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.