[Support request] Change logo for category and all sub-categories and products

Home Forums Support [Support request] Change logo for category and all sub-categories and products

Home Forums Support Change logo for category and all sub-categories and products

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1360641
    Marin

    Hi there! This awesome feature is great https://docs.generatepress.com/article/generate_logo/#example and I could use it for upgrading my project. But I would need to have same (changed) logo for all products and sub-categories within one category.

    I could find some solutions where I can put manually categories and products into filter but that is impractical for hundreds of products.

    Could you please let me know is there any “smart” way of doing this?

    #1361103
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    All of those products would need to have something in common. Are they all within or children of a specific parent category?

    #1361146
    Marin

    Yes, all products will be under same parent category.

    #1361283
    Tom
    Lead Developer
    Lead Developer

    It’s a tough one, but it’s possible. There are some solutions here worth looking at: https://stackoverflow.com/questions/20777929/woocommerce-how-do-i-get-the-most-top-level-category-of-the-current-product-ca

    For example:

    $categories = get_the_terms( $product->ID, 'product_cat' );
    $parent_cat = '';
    
    foreach ( $categories as $category ) {
        if ( $category->parent == 0 ) {
            $parent_cat = $category->name;
        }
    }
    
    if ( 'Parent Category Name' === $parent_cat ) {
        // do stuff for items with this parent category.
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.