WC_AJAX::json_search_taxonomy_terms
Search for taxonomy terms and return json.
Метод класса: WC_AJAX{}
Хуки из метода
Возвращает
void. Ничего (null).
Использование
$result = WC_AJAX::json_search_taxonomy_terms();
Код WC_AJAX::json_search_taxonomy_terms() WC AJAX::json search taxonomy terms WC 11.2.2
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.
*/
$args = apply_filters( 'woocommerce_product_attribute_terms', $args );
$terms = get_terms( $args );
$terms = self::maybe_include_exact_taxonomy_term( $terms, $args, $search_text, $taxonomy );
/**
* Filter the product attribute terms search results.
*
* @since 7.0.0
* @param array|WP_Error $terms The list of matched terms, or a term query error.
* @param string $taxonomy The terms taxonomy.
*/
wp_send_json( apply_filters( 'woocommerce_json_search_found_product_attribute_terms', $terms, $taxonomy ) );
}