WC_AJAX::json_search_downloadable_products_and_variations()public staticWC 1.0

Search for downloadable product variations and return json.

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

Хуки из метода

Возвращает

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

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

$result = WC_AJAX::json_search_downloadable_products_and_variations();

Заметки

Код WC_AJAX::json_search_downloadable_products_and_variations() WC 9.3.3

public static function json_search_downloadable_products_and_variations() {
	check_ajax_referer( 'search-products', 'security' );

	if ( ! empty( $_GET['limit'] ) ) {
		$limit = absint( $_GET['limit'] );
	} else {
		$limit = absint( apply_filters( 'woocommerce_json_search_limit', 30 ) );
	}

	$include_ids = ! empty( $_GET['include'] ) ? array_map( 'absint', (array) wp_unslash( $_GET['include'] ) ) : array();
	$exclude_ids = ! empty( $_GET['exclude'] ) ? array_map( 'absint', (array) wp_unslash( $_GET['exclude'] ) ) : array();

	$term       = isset( $_GET['term'] ) ? (string) wc_clean( wp_unslash( $_GET['term'] ) ) : '';
	$data_store = WC_Data_Store::load( 'product' );
	$ids        = $data_store->search_products( $term, 'downloadable', true, false, $limit );

	$product_objects = array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' );
	$products        = array();

	foreach ( $product_objects as $product_object ) {
		$products[ $product_object->get_id() ] = rawurldecode( wp_strip_all_tags( $product_object->get_formatted_name() ) );
	}

	wp_send_json( $products );
}