Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi updatediva,

    I’m not sure that you want your link structure to look like ?cat=(id-spring)+(id-candles). Instead I’d look into writing a custom loop. You can see the basic loop here:

    https://docs.woothemes.com/document/sample-products-loop/

    What happens if you do https://example.com/product-category/term1+term2/ ?

    Not sure if that resolves in WooCommerce or not. You may need to register a new rewrite rule if it won’t handle it out of the box.

    WordPress does a good job of handling ‘,’ (or) and ‘+’ (and) operators when parsing query strings so that may work.

    Thread Starter updatediva

    (@updatediva)

    Thanks for replying.

    It looks like I’m into creating a custom shortcode using a custom loop like you suggested. Does it make sense to change:

    $args = array(
    'post_type' => 'product',
    'posts_per_page' => 12
    );

    to:

    $args = array(
       'post_type' => 'product',
        'posts_per_page' => 12,
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'product_cat',
                'field' => 'slug',
                'terms' => 'category-slug1' /* first category I'm looking for
            ),
            array(
                'taxonomy' => 'product_cat',
                'field' => 'slug',
                'terms' => 'category-slug2' /* second category
            )
        ),
        'orderby' => 'title',
    );

    I’ve never created a shortcode before, but I’d copy class-wc-shorcodes.php to my child theme, add a new function called product_2categories (shortcode name), and regsiter it.

    Am I on the right track?

    Thread Starter updatediva

    (@updatediva)

    Unfortunately /?cat=”something+somethingelse” resolves really well in straight WordPress but not WooCommerce using product_cat and product_tag. You can do /?product_cat=”something” or /?product_tag=”something” but it can’t seem to handle operators.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom URL for multiple WooCommerce product categories in one link’ is closed to new replies.