Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_product_visibility_query()privateWC 1.0

Return a query for product visibility depending on their stock status.

Method of the class: ProductQuery{}

No Hooks.

Return

Array. Tax query for product visibility.

Usage

// private - for code of main (parent) class only
$result = $this->get_product_visibility_query( $stock_query );
$stock_query(array) (required)
Stock status query.

ProductQuery::get_product_visibility_query() code WC 8.9.0

private function get_product_visibility_query( $stock_query ) {
	$product_visibility_terms  = wc_get_product_visibility_term_ids();
	$product_visibility_not_in = array( is_search() ? $product_visibility_terms['exclude-from-search'] : $product_visibility_terms['exclude-from-catalog'] );

	// Hide out of stock products.
	if ( empty( $stock_query ) && 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
		$product_visibility_not_in[] = $product_visibility_terms['outofstock'];
	}

	return array(
		'tax_query' => array(
			array(
				'taxonomy' => 'product_visibility',
				'field'    => 'term_taxonomy_id',
				'terms'    => $product_visibility_not_in,
				'operator' => 'NOT IN',
			),
		),
	);
}