1. PROMO Upgrade to Pro Membership @ $99 / Lifetime & access all our 16+ premium Divi extensions: Divi Block, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Solved Is there a Divi module that outputs a list of the categories

Discussion in 'Free Divi Community Forum' started by Grant Senior, Jan 10, 2024.

  1. Grant Senior

    Grant Senior Member

    Hi there,

    Is there a module that generates a list of the categories from the Woo Commerce system? I've found the Woo Products module that will list items in a category, but I'd like a module that lists the categories themselves. As per the screenshot below.

    categories-page.jpg
     
    1. PRO MEMBER PERKS Divi Powerful Child Theme - Power up your Divi sites with tons of new functionalities & premade elements:Learn More
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    You will need to use Woocommerce shortcode to display it: [product_categories]

    You may check out this thread: https://divi.help/threads/how-can-i-show-a-list-of-woocommerce-categories-on-a-page.4234/
     
    GiuseppeM likes this.
  3. Grant Senior

    Grant Senior Member

    Thanks, I've just found it and looked at it, but it's very limited and will take a lot of code to customize it to get what I want. Unless I find a better approach, I think I'll just have create them manually using another module with a link.
     
    1. PRO MEMBER PERKS Divi Ultimate Header Plugin - Add more varieties for your Divi header (12 premade styles) + menu hover effects:Learn More
  4. Grant Senior

    Grant Senior Member

    Further update - Just thought you might like to know, I've tried the shortcode idea again, but I used ChatGPT to generate a function that only output the parent categories I wanted listed and once that was working, refined the function to output the html I needed for styling. This has worked pretty well, so far.
     
  5. Grant Senior

    Grant Senior Member

    Adding to this, for those that may not be aware, the function that ChatGPT created was added to the Divi theme function.php file to work.
     
    1. PRO MEMBER PERKS Divi Block Pro - Easy-to-use drag & drop interface to mix & match 456+ premade Divi blocks & export as json file:Learn More
  6. Grant Senior

    Grant Senior Member

    Though it might be more helpful if I actually included the code.

    The shortcode it uses is [parent_product_categories]

    The following function gets placed in the Divi themes 'functions.php' file.



    function display_parent_product_categories() {
    $args = array(
    'taxonomy' => 'product_cat',
    'parent' => 0, // Set to 0 to retrieve only parent categories
    'hide_empty' => false,
    );

    $categories = get_terms($args);

    if ($categories) {
    $output = '<div class="parent-category">';

    foreach ($categories as $category) {
    $image_url = get_term_meta($category->term_id, 'thumbnail_id', true);
    $image_url = wp_get_attachment_url($image_url);

    $output .= '<div class="category-item">';
    $output .= '<h2 class="cat-title">' . esc_html($category->name) . '</h2>';

    // Get the total number of products in the category
    $product_count = $category->count;
    $output .= '<p class="cat-prods-total">' . $product_count . ' Products</p>';

    // Display category image
    if ($image_url) {
    $output .= '<img src="' . esc_url($image_url) . '" alt="' . esc_attr($category->name) . '" class="prod-cat-img">';
    }

    // Button to see the range
    $category_link = get_term_link($category->term_id, 'product_cat');
    $output .= '<a href="' . esc_url($category_link) . '" class="cat-see-range">SEE RANGE</a>';

    $output .= '</div>'; // Close category-item
    }

    $output .= '</div>'; // Close parent-category
    return $output;
    } else {
    return 'No parent product categories found.';
    }
    }
    add_shortcode('parent_product_categories', 'display_parent_product_categories');