Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23738

    Hi there,

    on a single product page I would like the top title to be the category that the product resides in rather than the generic “shop” title.

    Is this possible – can I replace the title code somewhere?

    thanks

    #120963

    In wp-contentthemesrepleteconfig-woocommerceconfig.php replace

    if(is_product_category() || is_product_tag())
    {
    global $wp_query;
    $tax = $wp_query->get_queried_object();
    $title = $tax->name;
    $t_link = '';
    }

    with

    if(is_product_category() || is_product_tag())
    {
    global $wp_query;
    $tax = $wp_query->get_queried_object();
    $title = $tax->name;
    $t_link = '';
    }

    if(is_product())
    {
    global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    foreach ($terms as $term) {
    $title = $term->name;
    break;
    }
    }

    #120964

    Hi,

    I also prefere what nikicampbell is looking for, but in config.php there is no such code, I only can find this on line 367 (the only place I find if(is_product()) ) :

    // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
    if(is_product())
    {
    //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
    $product_category = $parent_cat = array();
    $temp_cats = get_the_terms(get_the_ID(), $taxonomy);

    if(!empty($temp_cats))
    {
    foreach($temp_cats as $key => $cat)
    {
    if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat))
    {
    $product_category[] = $cat;
    $parent_cat[] = $cat->parent;
    }
    }

    //if no categories with parents use the first one
    if(empty($product_category)) $product_category[] = reset($temp_cats);

    }
    //unset the trail and build our own
    unset($trail);

    $trail[0] = $home;
    if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) );
    if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) );
    if(!empty($product_category)) $trail[] = '<a href="' . get_term_link( $product_category[0]->slug, $taxonomy ) . '" title="' . esc_attr( $product_category[0]->name ) . '">' . $product_category[0]->name . '</a>';

    }

    // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
    if(is_product_category() || is_product_tag())
    {
    if(!empty($shop_id) && $shop_id != -1)
    {
    $shop_trail = avia_breadcrumbs_get_parents( $shop_id ) ;
    array_splice($trail, 1, 0, $shop_trail);
    }
    }

    if(is_product_tag())
    {
    $last = __("Tag",'avia_framework').": ".$last;
    }

    if(!empty($last)) $trail[] = $last;
    }

    return $trail;
    }

    #120965

    Hi!

    My mistake I corrected the instructions above.

    Best regards,

    Peter

    #120966

    great, works, thanks!

    Tom

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘On single product page >> can the title be the category rather than "shop"’ is closed to new replies.