Shop Page Default views on product categories page, different default views for different categories

This topic has 2 replies, 2 voices, and was last updated 1 years, 6 months ago ago by Rose Tyler

  • Avatar: Kris
    Kris
    Participant
    May 11, 2023 at 07:30

    Hello support team,

    Wondering if I can set different default views (list vs grid view) for different categories page?

    For example:
    I have 2 main categories of products, and sub-categories of each:
    —- Vegetables
    |——— Broccoli
    |——— Cabbage
    —- Fruits
    |——— Apple
    |——— Orange

    I would like to have default list view for all vegetable categories pages:
    /product-category/vegetables/
    /product-category/vegetables/Broccoli/
    /product-category/vegetables/Cabbage/

    and have grid view for fruits categories pages:
    /product-category/fruits/
    /product-category/fruits/apple/
    /product-category/fruits/oranges/

    Is it possible? that would be very helpful for us. Thank you

    Please, contact administrator
    for this information.
    1 Answer
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    May 11, 2023 at 12:14

    Hello, Kris,

    Thank you for contacting us and for using XStore.

    It is possible to customize the child theme by adding the following code to wp-content/themes/xstore-child/functions.php:

    add_action('wp', 'et_child_grid_list_query', 2);
    
    function et_child_grid_list_query(){
        if( is_product_category( array( 35, 10, 891 ) ) ) {
            set_query_var( 'et_view-mode', 'list' );
        } elseif( is_product_category( array( 35, 10, 891 ) ) ) {
            set_query_var( 'et_view-mode', 'grid' );
        }
    }

    After that, you need to replace the category IDs with the ones you want to use for the respective view. The category IDs can be found in the category editor, as shown in the screenshot: https://prnt.sc/Pn4mA8fEmP8L

    Kind Regards,
    8theme team

  • Viewing 2 results - 1 through 2 (of 2 total)

The issue related to '‘Shop Page Default views on product categories page, different default views for different categories’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.