WC_AJAX::json_search_taxonomy_terms()public staticWC 1.0

Search for taxonomy terms and return json.

Метод класса: WC_AJAX{}

Возвращает

null. Ничего.

Использование

$result = WC_AJAX::json_search_taxonomy_terms();

Код WC_AJAX::json_search_taxonomy_terms() WC 7.1.0

public static function json_search_taxonomy_terms() {
	ob_start();

	check_ajax_referer( 'search-taxonomy-terms', 'security' );

	if ( ! current_user_can( 'edit_products' ) ) {
		wp_die( -1 );
	}

	$search_text = isset( $_GET['term'] ) ? wc_clean( wp_unslash( $_GET['term'] ) ) : '';
	$limit       = isset( $_GET['limit'] ) ? absint( wp_unslash( $_GET['limit'] ) ) : null;
	$taxonomy    = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : '';

	$args = array(
		'taxonomy'        => $taxonomy,
		'orderby'         => 'id',
		'order'           => 'ASC',
		'hide_empty'      => false,
		'fields'          => 'all',
		'number'          => $limit,
		'name__like'      => $search_text,
		'suppress_filter' => true,
	);

	/**
	 * Filter the product attribute term arguments used for search.
	 *
	 * @since 3.4.0
	 * @param array $args The search arguments.
	 */
	$terms = get_terms( apply_filters( 'woocommerce_product_attribute_terms', $args ) );

	/**
	 * Filter the product attribute terms search results.
	 *
	 * @since 7.0.0
	 * @param array  $terms    The list of matched terms.
	 * @param string $taxonomy The terms taxonomy.
	 */
	wp_send_json( apply_filters( 'woocommerce_json_search_found_product_attribute_terms', $terms, $taxonomy ) );
}