Settings > Pages tab): * - woocommerce_prepend_shop_page_to_urls (breadcrumbs and permalinks) * - woocommerce_prepend_shop_page_to_products (permalinks only) * - woocommerce_prepend_category_to_products (permalinks only) * * @since 1.0.0 */ add_filter( 'bizznis_archive_crumb', 'bizznis_wc_get_archive_crumb_filter', 10, 2 ); function bizznis_wc_get_archive_crumb_filter( $crumb, $args ) { # Are we on the product archive page? if ( is_post_type_archive( 'product') && get_option( 'page_on_front' ) !== woocommerce_get_page_id( 'shop' ) ) { $shop_id = woocommerce_get_page_id( 'shop' ); $shop_name = $shop_id ? get_the_title( $shop_id ) : ucwords( get_option('woocommerce_shop_slug') ); if ( is_search() ) { $crumb = bizznis_wc_get_crumb_link( get_post_type_archive_link( 'product' ), $shop_name, $shop_name, $args['sep'] . __( 'Search results for “', 'bizznis' ) . get_search_query() . '”' ); } else { $crumb = $shop_name; } return apply_filters( 'bizznis_wc_product_archive_crumb', $crumb, $args ); } # Are we on a shop taxonomy archive page? if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) { $crumb = ''; $prepend = ''; # Should we prepend crumb with 'shop' page link? # See Dashboard > WooC Settings > Pages tab $shop_url = get_option( 'woocommerce_prepend_shop_page_to_urls' ); $shop_id = woocommerce_get_page_id( 'shop' ); $shop_title = get_the_title( $shop_id ); if ( 'yes' == $shop_url && $shop_id && get_option( 'page_on_front' ) !== $shop_id ) { $prepend = bizznis_wc_get_crumb_link( get_permalink( $shop_id ), $shop_title, $shop_title, $args['sep'] ); } } if ( is_tax( 'product_cat' ) ) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $parents = array(); $parent = $term->parent; while ( $parent ) { $parents[] = $parent; $new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) ); $parent = $new_parent->parent; } $crumb .= $prepend; if ( ! empty( $parents ) ) { $parents = array_reverse( $parents ); foreach ( $parents as $parent ) { $item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) ); $crumb .= bizznis_wc_get_crumb_link( get_term_link( $item->slug, 'product_cat' ), $item->name, $item->name, $args['sep'] ); } } $crumb .= single_term_title( '', false ); return $crumb; } if ( is_tax( 'product_tag' ) ) { $crumb .= $prepend . __( 'Products tagged “', 'bizznis' ) . single_term_title( '', false ) . _x( '”', 'endquote', 'bizznis' ); return $crumb; } # Original unmodified return $crumb; } /** * Filter the Bizznis Breadcrumbs singular crumb * * Needed for single Product pages * * @since 1.0.0 */ add_filter( 'bizznis_single_crumb', 'bizznis_wc_get_single_crumb', 10, 2 ); function bizznis_wc_get_single_crumb( $crumb, $args ) { # Are we on a single product page? if ( is_singular( 'product' ) ) { $crumb = ''; $prepend = ''; # Should we prepend crumb with 'shop' page link? # See Dashboard > WooC Settings > Pages tab $shop_url = get_option( 'woocommerce_prepend_shop_page_to_urls' ); $shop_id = woocommerce_get_page_id( 'shop' ); $shop_title = get_the_title( $shop_id ); if ( 'yes' == $shop_url && $shop_id && get_option( 'page_on_front' ) !== $shop_id ) { $prepend = bizznis_wc_get_crumb_link( get_permalink( $shop_id ), $shop_title, $shop_title, $args['sep'] ); } $crumb .= $prepend; if ( $terms = wp_get_object_terms( get_the_ID(), 'product_cat' ) ) { $term = current( $terms ); $parents = array(); $parent = $term->parent; while ( $parent ) { $parents[] = $parent; $new_parent = get_term_by( 'id', $parent, 'product_cat' ); $parent = $new_parent->parent; } if( ! empty( $parents ) ) { $parents = array_reverse( $parents ); foreach ( $parents as $parent ) { $item = get_term_by( 'id', $parent, 'product_cat' ); $crumb .= bizznis_wc_get_crumb_link( get_term_link( $item->slug, 'product_cat' ), $item->name, $item->name, $args['sep'] ); } } $crumb .= bizznis_wc_get_crumb_link( get_term_link( $term->slug, 'product_cat' ), $term->name, $term->name, $args['sep'] ); } $crumb .= get_the_title(); return apply_filters( 'bizznis_wc_single_product_crumb', $crumb, $args ); } # Fallback - original unmodified return $crumb; } /** * Helper function to create anchor link for a single crumb. * * This is a copy of Bizznis_Breadcrumb::get_breadcrumb_link() (G1.8) * * @since 1.0.0 */ function bizznis_wc_get_crumb_link( $url, $title, $content, $sep = false ) { $link = sprintf( '%s', esc_attr( $url ), esc_attr( $title ), esc_html( $content ) ); if ( $sep ) { $link .= $sep; } return $link; }