• Hey, have some concerns over my web shop. The thing is i have allot of “different products”, and also on my shop page i want to show only products from “one category”, and the rest are on other places. So basically in my functions.php i have something like

    function custom_pre_get_posts_query( $q ) {
    
    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;
    
    if ( ! is_admin() && is_shop() ) {
    
        $q->set( 'tax_query', array(array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'somecat1', 'somecat2' ),
            'operator' => 'IN'
        )));
    
    }

    and that sorts out my SHOP page to display only those two categories. Some of my other categories should have different single product page, i managed to do that with

    if( !has_term( ['cat3','cat4'], 'product_cat' ) ) {
                        wc_get_template_part .....

    and that also works. But now i placed WPML and i have some issues. So i am wondering, is this good approach to this. Because i have allot of categories that are maybe not needed. Lets say i have category “in-shop” so i can mark products that will be only on shop page, and i filter them by this function in functions.php. Then i have actual cat of that product – lets say STUFF and i need to mark it as well, and things like that. And that can be prety confusing since im using cats as tags so to say… Then lets say i have category “selected4” which displays 4 products on my homepage where i want over

    $args = array(
                'post_type' => 'product',
        'product_cat' => 'selected4',
                'posts_per_page' => 3,
                'meta_query' => array(
                array(
                'key' => '_hide_if_out_of_stock',
                'compare' => 'NOT EXISTS'
                ))
                ); ......

    That all works, but im wondering is there a better way to do this? Because im worried later if i have some filter plugin, it will include all categories on my shop page and i dont want it. Can it be done over tags or something since they are not hierarchical? But i dont know if i can use my loops and place product_tag instead of product_cat. I now i cant in my functions.php in the manner of current function lets say. Also on only one type of product i would need accordion of its categories and number of each subcat items. How to achieve this?

    Sory for long post. All advices are wellcome

    https://wordpress.org/plugins/woocommerce/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Your first code is fine, but you’ll need to include the slugs of the WPML translated terms too for it to work in all languages. You may want to post on the WPML forum – they have helper functions to get translated versions of categories.

    Thread Starter junior

    (@epiric)

    Thanks, is it good approach to differ products by categories? I mean if i have CAT1 that has one design and CAT2 that has other design (shop page and/or single product page), and then make actual categories, lets say,
    CAT1 is used to STYLE categories CAR, BIKE, BLA, and CAT2 is used to style PLATES, CHAIRS.
    So when i add product i select CAT1 and BIKE for categories. Or is that bad?

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Thats sounds valid. Categories can have a hierarchy so I don’t see whats wrong with that.

    Thread Starter junior

    (@epiric)

    Thanks, and does then CAT1 has to be parrent of those categories, or its not needed? Since i actually dont need it in URL, i just need it as MARK so i can target coding in php, since its easier to target 1 category, then 5 of them separate.

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    I’d need to know more about the structure/products etc to advise on this. It depends.

    Thread Starter junior

    (@epiric)

    Aha, ill try to type it, and then i wont bother you anymore.

    So i have categories of DOG BREEDS, like big dogs, small dogs, etc, then i have subcategories of those, like big dogs (sheperd), etc, and then small puppies as ending product.

    Then i have lets say actual products like articles, so eating bowls, cases etc and each of those has product on end.

    Then, since i wanted puppies to have different shop layout, and ending single product layout, i made adittional category called DOGS, and one called ITEMS, and then in my functions.php for main shop i just show from ITEMS category. And on other place i show DOGS.

    And i use those product_cat to display different single product page for pippies and for items. So when i add new puppy i select category DOGS, and lets say shepered. And when i add new bowl i select ITEMS and bowl for categories.

    In that case, does DOGS and ITEMS need to be parrent categorie or not?

    Thanks allot, after this i wont bother you

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Can you screenshot that structure for me so it’s clearer?

    I don’t know what you mean by articles/items. You’re not selling dogs, so I don’t understand what you need an ‘items’ category.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘complex stuff in webshop’ is closed to new replies.