Support » Plugin: WooCommerce » How to add meta_query to the main products query?

  • Resolved ianwp

    (@ianwp)


    Hi.
    I added a check box to show or hide certain products from the loop.
    I already modified some of the templates shortcodes to use the meta_query parameter, however I do NOT WANT to modify the core Woocommerce files.

    Is there a way to hook the $args[‘meta_query’] = array(…) to every query made on is_tax(‘product_cat’) and is_tax(‘product_tag’) ?

    Thanks!

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Done!
    The hook comes from WP, not WooCommerce 😀

    function wc_add_meta_query($query) {
    	if (is_tax('product_cat')) {
    		$query->set('meta_key', 'field_name');
    	}
    }
    add_filter('pre_get_posts','wc_add_meta_query');
Viewing 1 replies (of 1 total)
  • The topic ‘How to add meta_query to the main products query?’ is closed to new replies.