complex stuff in webshop
-
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
- The topic ‘complex stuff in webshop’ is closed to new replies.