• Resolved o0MSK0o

    (@o0msk0o)


    I’m not sure if this is the right place to ask for these sorts of questions, but I was wondering if anyone had any suggestions for a clean way to add things within the category list in the archive page.

    My design looks like this: https://imgur.com/a/fb6NrMZ

    It has a section within the category list advertising a sale. But I cannot think of a clean way to add that–displaying that isn’t a problem but displaying it *in the right place* is.

    The category list is displayed through the woocommerce_maybe_show_product_subcategories function (hooked into the woocommerce_product_loop_start filter) which calls woocommerce_output_product_categories to actually output the list.

    Since the loop for displaying categories is inside a function (as opposed to within a template) I’m not sure how I’d go about modifying it.

    All I can think of is duplicating both functions and changing my maybe_show_product_subcategories function to use the duplicated output_product_categories function, then removing the original filter and adding my updated one.

    That feels very messy though, and like it might break something in a future update. Any suggestions for a clean way to change it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I would think any change to your list of categories would break such a setup however it was coded.

    You could make your own custom shop page using shortcodes interspersed with your the other content.
    https://docs.woocommerce.com/document/woocommerce-shortcodes/

    Use a redirect plugin to push shop links to your custom shop page.

    Thread Starter o0MSK0o

    (@o0msk0o)

    Hi @lorro,

    Thanks for the response.

    I would think any change to your list of categories would break such a setup however it was coded.

    What do you mean? Do you mean in terms of breaking the layout? That shouldn’t be a problem–I just need to make sure it’s only output every three items. If I can edit the PHP within the loop that won’t be a problem–I just need to add a variable containing the current category count and check ($i%3===0). E.g.

            foreach ( $product_categories as $i=>$category ) {
                wc_get_template(
                    'content-product_cat.php',
                    array(
                        'category' => $category,
                    )
                );
                if($i%3===0) {
                    // output sales ad
                }
            }

    It’s just that I didn’t want to have to recreate the woocommerce_output_product_categories function. I want this to be in the theme, so I think that’s the route I’ll have to take–though it does feel very messy.

    Thanks for trying to help.

    • This reply was modified 4 years, 5 months ago by o0MSK0o.
    • This reply was modified 4 years, 5 months ago by o0MSK0o.

    That looks like a good fix and shouldn’t break the layout.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Inserting things into category list’ is closed to new replies.