WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] How to add meta_query to the main products query? (2 posts)

  1. ianwp
    Member
    Posted 1 year ago #

    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/

  2. ianwp
    Member
    Posted 1 year ago #

    Done!
    The hook comes from WP, not WooCommerce :D

    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');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic