• Resolved richiekastl

    (@richiekastl)


    Hello,

    My client has a huge amount of categories on their site, and a majority of their products have multiple categories. It seems like this plugin is only bringing in one set of related categories based on one of the product’s categories. My client would like to bring in related categories based on the category the user was browsing in.

    Say product A is in X, Y, and Z categories. By default, the related categories that are shown are based on category X. A customer is browsing category Z and visits product A. My client would like the related categories to be based on category Z instead of category X (the default).

    Is this possible? I could capture the slug of the category the customer is browsing and then feed it into a filter if there is one.

    Thank you for your time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Algoritmika

    (@algoritmika)

    Hi @richiekastl,

    Sorry for the late reply. I’m not receiving most of the notifications from wp.org recently, really sorry about that.

    Let me test it on my server and get back to you…

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @richiekastl,

    Again sorry for the late reply.

    I can definitely add some filter(s) to the plugin, however, before that, I would like to understand the task better.

    First of all – you are referring to our plugin’s “Single” section, correct (i.e. not “Archives”)?

    Now regarding “… related categories that are shown are based on category X…” – let’s say a product has categories X, Y, and Z, as you’ve described. Now if each of these categories has one child category (X1, Y1, and Z1 accordingly), and we have enabled “Relate Options > Children” in our plugin, then on a single product page all three child categories are displayed (i.e. X1, Y1, and Z1). That is – related categories are based on all product’s categories, not just one of them. Or did I misunderstand what you meant?

    So in conclusion, if I’m getting the task correctly, what we actually need is a filter to restrict current product categories. That is, if our categories are based on X, Y, and Z, we may want to exclude, for example, X and Z, in case if a customer visited category Y recently.

    Please let me know what you think.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @richiekastl,

    I went ahead and added a filter (in the plugin v1.9.1) to filter current product categories:

    alg_wc_related_categories_single_product_category_ids
    

    So following my previous example, let’s say the product has three categories: X, Y, and Z. And IDs of those categories are 100, 101, and 102 respectively. So if we decided that the recently visited category is Y (ID: 101), we can exclude the remaining categories with this PHP snippet:

    add_filter( 'alg_wc_related_categories_single_product_category_ids', function( $product_category_ids, $product ) {
        $recently_visited_category = 101; // do your magic here, e.g. use session to track recently visited category
        if ( in_array( $recently_visited_category, $product_category_ids ) ) {
            // if current product belongs to the recently visited category, we want to remove all other categories for this product
            return array( $recently_visited_category );
        }
        return $product_category_ids;
    }, 10, 2 );

    Please let me know what you think.

    Plugin Author Algoritmika

    (@algoritmika)

    I’m going to mark this thread as “resolved” for now, hope that’s ok. Please let me know if there are still any questions/issues.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Products Have Multiple Related Categories’ is closed to new replies.