Forum Replies Created

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

    (@dsd87)

    Okay, I think that I’m getting there. For others that have the same requirement here is what I did.

    I created 3 menus
    shop – /shop
    new-products – /shop?new=1
    sales – /shop?sale=1

    I created a plugin that intercepts the woocommerce_product_query

    function cjwc_product_query( $q ){
    
        $uri = $_SERVER['REQUEST_URI'];
    
        if(strstr($uri, 'sale=1')) {
    	    $product_ids_on_sale = wc_get_product_ids_on_sale();
    
    	    $q->set( 'post__in', (array) $product_ids_on_sale );
        }
    
    	if(strstr($uri, 'new=1')) {
    		$q->set('date_query', array(
    			array(
    
    				'after' => "15 day ago"
    			)
    		));
    	}
    }
    
    add_action( 'woocommerce_product_query', 'cjwc_product_query' );

    So basically when the request url has sale or new in it I override the default woocommerce query and only look for products_on_sale or products from the last 15 days.

    The categories widget is a little more complicated. I wrote my own widget and overwrote the Categories_Walker. My widget has an option to append a suffix to the url. I’ve created 3 widgets – one for the normal products, one for new and one for sales.

    new appends new=1 and sale appends sale=1 to the category urls.

    This way I’m always reusing the shop page, but returning the filtered results.

    At first I was using add_filter(‘term_link’, …) but this doesn’t work for me as I’m loading all the categories in a submenu. (all categories for new, for sale and for all products) And those categories needed to have all different suffixes. So it was necessary to write my own widget.

    I still have to modify other widget such as price, color etc to also append the suffix, but yea…

    If anyone has a better idea, please let me know!

    Thread Starter dsd87

    (@dsd87)

    Thanks for the reply. Unfortunately with shortcodes I can only display the products – sales, new, but I can’t have any kind of filtering on that page…

    That’s a bummer.

Viewing 2 replies - 1 through 2 (of 2 total)