• Resolved marvelfreak

    (@marvelfreak)


    Hello lets say i want specific breadcrumbs in product page.

    I have problem. I want that breadcrumbs would show only parent or child category which is not empty if empty – ignore not to show. As you can see in screenshots “Berzu degutas”,”akcijos” i need ignore because does not have childs. Only to show Higiena ir kosmetika > prausimosi priemones > muilai. How to do that ?

    i have my code: (need to fix )

    if ( is_product() ) {
    global $product;
    $categories = get_the_terms( $product->get_id(), 'product_cat' );
    if ( $categories && ! is_wp_error( $categories ) ) {
    $category_names = array();
    $previous_category = '';
    foreach ( $categories as $category ) {
    if ( $category->parent == 0 ) {
    // If it's a top-level category, add it to the breadcrumb trail
    if ($category->name !== $previous_category) {
    $category_names[] = '<span class="first">'. $category->name. '</span>';
    }
    } else {
    // If it's a child category, add it to the breadcrumb trail only if it's different from the previous one
    if ($category->name !== $previous_category) {
    $category_names[] = '<span class="second">'.$category->name. '</span>';
    }
    }
    $previous_category = $category->name; // Update the previous category
    }
    // Generate the breadcrumb trail
    $breadcrumb = implode(' > ', $category_names);
    
    // Check if the breadcrumb trail has already been displayed
    static $displayed_breadcrumbs = array();
    if (!in_array($breadcrumb, $displayed_breadcrumbs)) {
    echo '<p>' .$breadcrumb . '</p> <br>';
    $displayed_breadcrumbs[] = $breadcrumb; // Store the displayed breadcrumb trail
    }
    }
    }

    https://ibb.co/ZmD5HjH
    https://ibb.co/CHbGFvT
    https://ibb.co/VNQtHf0

    • This topic was modified 10 months, 4 weeks ago by marvelfreak.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocommerce product page breadcrumbs’ is closed to new replies.