• Resolved markelovett

    (@markelovett)


    Upon selecting a custom attribute value in the menu, I want to display archive pages with products associated with the custom attribute values only.

    For example, when a user selects ‘Arizona State’ in the ‘Find Your School’ menu, an archive page displays all products associated with Arizona school only.

    In my dev site at https://affinitygamerooms.marklovettstudio.com/ , I set up ‘Pool Tables’ as a variable product, ‘Find Your School’ as an attribute, and schools are entered as attribute values. I created many other variable products using the same 60 schools as custom attribute values.

    To test, I have entered data in the first three schools only …. Air Force Academy, Arizona State and Army West Point, the other schools are empty.
    When user selects a school in the “Find Your School’ menu, I want to display only products associated with the particular school, however now, upon selecting ‘Arizona State’, although the permalink is ‘https://affinitygamerooms.marklovettstudio.com/pa_find-your-school/arizona-state-university/’ , products display in an archive page from Air Force Academy.
    Similarly, when I select the ‘Army West Point’ from the ‘Find Your School’ menu, the permalink appears correct, https://affinitygamerooms.marklovettstudio.com/pa_find-your-school/army-west-point/, however the products that display are for Air Force Academy as well.
    The code I added to my child theme functions.php is:

    add_filter(‘woocommerce_attribute_show_in_nav_menus’, ‘wc_reg_for_menus’, 1, 2);

    function wc_reg_for_menus( $register, $name = ” ) {
    if ( $name == ‘pa_find-your-school’ ) $register = true;
    return $register;
    }

    Will someone please help me display archive pages with products associated with the custom attribute value only?

    Thanks much,
    Mark
    [email protected]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter markelovett

    (@markelovett)

    Per instructions given here: https://docs.woocommerce.com/document/using-custom-attributes-in-menus/

    1-Added following code to my child theme functions.php:

    add_filter(‘woocommerce_attribute_show_in_nav_menus’, ‘wc_reg_for_menus’, 1, 2);
    function wc_reg_for_menus( $register, $name = ” ) {
    if ( $name == ‘pa_find-your-school’ ) $register = true;
    return $register;
    }

    2) Copied woocommerce/templates/taxonomy-product_cat.php into my child theme folder and renamed template to mychildtheme/woocommerce/templates/taxonomy-pa_find-your-school.php

    Then I cleared my varnish cache and refreshed the site several times but no change. Both schools, Arizona State and Army West Point still display Air Force Academy products.

    Help!

    Thread Starter markelovett

    (@markelovett)

    The find-your-school attribute was set up as a global attribute with ‘Enable Archives’ box checked.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Select custom attribute value in menu to display product archive’ is closed to new replies.