wc_get_product_visibility_term_ids()WC 3.0.0

Get full list of product visibility term ids.

No Hooks.

Returns

Int[].

Usage

wc_get_product_visibility_term_ids();

Changelog

Since 3.0.0 Introduced.

wc_get_product_visibility_term_ids() code WC 10.8.1

function wc_get_product_visibility_term_ids() {
	if ( ! taxonomy_exists( 'product_visibility' ) ) {
		wc_doing_it_wrong( __FUNCTION__, 'wc_get_product_visibility_term_ids should not be called before taxonomies are registered (woocommerce_after_register_post_type action).', '3.1' );
		return array();
	}

	static $term_ids_by_blog = array();

	$blog_id = get_current_blog_id();

	if ( isset( $term_ids_by_blog[ $blog_id ] ) && ! class_exists( 'WC_Unit_Tests_Bootstrap' ) ) {
		return $term_ids_by_blog[ $blog_id ];
	}

	$term_ids_by_blog[ $blog_id ] = array_map(
		'absint',
		wp_parse_args(
			wp_list_pluck(
				get_terms(
					array(
						'taxonomy'   => 'product_visibility',
						'hide_empty' => false,
					)
				),
				'term_taxonomy_id',
				'name'
			),
			array(
				'exclude-from-catalog' => 0,
				'exclude-from-search'  => 0,
				'featured'             => 0,
				'outofstock'           => 0,
				'rated-1'              => 0,
				'rated-2'              => 0,
				'rated-3'              => 0,
				'rated-4'              => 0,
				'rated-5'              => 0,
			)
		)
	);

	return $term_ids_by_blog[ $blog_id ];
}