WC_AJAX::json_search_taxonomy_terms
Search for taxonomy terms and return json.
Method of the class: WC_AJAX{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_AJAX::json_search_taxonomy_terms();
WC_AJAX::json_search_taxonomy_terms() WC AJAX::json search taxonomy terms code WC 10.5.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'] ) ) : '';
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : 'name';
$order = isset( $_GET['order'] ) ? wc_clean( wp_unslash( $_GET['order'] ) ) : 'ASC';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'order' => $order,
'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 ) );
}