WordPress at Your Fingertips
function is not described

WC_Query::product_query() public WC 1.0

Query the products, applying sorting/ordering etc. This applies to the main WordPress loop.

{} It's a method of the class: WC_Query{}

Return

null. Nothing.

Usage

$WC_Query = new WC_Query();
$WC_Query->product_query( $q );
$q(WP_Query) (required)
Query instance.

Code of WC_Query::product_query() WC 5.8.0

public function product_query( $q ) {
	if ( ! is_feed() ) {
		$ordering = $this->get_catalog_ordering_args();
		$q->set( 'orderby', $ordering['orderby'] );
		$q->set( 'order', $ordering['order'] );

		if ( isset( $ordering['meta_key'] ) ) {
			$q->set( 'meta_key', $ordering['meta_key'] );
		}
	}

	// Query vars that affect posts shown.
	$q->set( 'meta_query', $this->get_meta_query( $q->get( 'meta_query' ), true ) );
	$q->set( 'tax_query', $this->get_tax_query( $q->get( 'tax_query' ), true ) );
	$q->set( 'wc_query', 'product_query' );
	$q->set( 'post__in', array_unique( (array) apply_filters( 'loop_shop_post_in', array() ) ) );

	// Work out how many products to query.
	$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );

	// Store reference to this query.
	self::$product_query = $q;

	// Additonal hooks to change WP Query.
	add_filter(
		'posts_clauses',
		function( $args, $wp_query ) {
			return $this->product_query_post_clauses( $args, $wp_query );
		},
		10,
		2
	);
	add_filter( 'the_posts', array( $this, 'handle_get_posts' ), 10, 2 );

	do_action( 'woocommerce_product_query', $q, $this );
}