• 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 11 months ago by marvelfreak.

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Stef

    (@serafinnyc)

    Your code wouldn’t work or is formatted incorrectly

    Please have a look here on our doc page about customizing the breadcrumbs. Hope this helps

    Thread Starter marvelfreak

    (@marvelfreak)

    i added in to private function print_breadcrumbs() { }

    framework/addons/breadcrumb/class-alpha-breadcrumbs

    Stef

    (@serafinnyc)

    Not sure what you mean, but just letting you know it’s formatted wrong. Read the docs and let me know.

    Thread Starter marvelfreak

    (@marvelfreak)

    I want to avoid parent category dublicating and if parent category has no child ignore. How i can do that ?

    Stef

    (@serafinnyc)

    I don’t see anything replicating https://loom.com/i/bd8e0cbc5c1145ba9b61fe34c117b4c7

    Hey there! Thanks for contacting us.

    I see @serafinnyc is already helping you with the code ??

    While we (Woo Support) can’t help with that as per our support policy, we do our best to offer advice and direct you to appropriate resources.

    In case you need it, let me share other great places to get help with code customization: WooCommerce Facebook group and the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there too.

    Please let us know if there’s anything else we can do to help or if you have any questions.

    Have a wonderful day!

    Hi ?? We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

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