WC_AJAX::json_search_product_attributes()public staticWC 1.0

Search for product attributes and return json.

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

Возвращает

null. Ничего (null).

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

$result = WC_AJAX::json_search_product_attributes();

Код WC_AJAX::json_search_product_attributes() WC 8.7.0

public static function json_search_product_attributes() {
	ob_start();

	check_ajax_referer( 'search-product-attributes', 'security' );

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

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

	$attributes = wc_get_attribute_taxonomies();

	$found_product_categories = array();

	foreach ( $attributes as $attribute_obj ) {
		if ( ! $search_text || false !== stripos( $attribute_obj->attribute_label, $search_text ) ) {
			$found_product_categories[] = array(
				'id'           => (int) $attribute_obj->attribute_id,
				'name'         => $attribute_obj->attribute_label,
				'slug'         => wc_attribute_taxonomy_name( $attribute_obj->attribute_name ),
				'type'         => $attribute_obj->attribute_type,
				'order_by'     => $attribute_obj->attribute_orderby,
				'has_archives' => (bool) $attribute_obj->attribute_public,
			);
		}
		if ( count( $found_product_categories ) >= $limit ) {
			break;
		}
	}

	/**
	 * Filter the product category search results.
	 *
	 * @since 7.0.0
	 * @param array   $found_product_categories Array of matched product categories.
	 * @param string  $search_text              Search text.
	 */
	wp_send_json( apply_filters( 'woocommerce_json_search_found_product_categories', $found_product_categories, $search_text ) );
}