WordPress at Your Fingertips
function is not described

WC_AJAX::json_search_downloadable_products_and_variations() public WC 1.0

Search for downloadable product variations and return json.

{} It's a method of the class: WC_AJAX{}

Hooks from the method

Return

null. Nothing.

Usage

$result = WC_AJAX::json_search_downloadable_products_and_variations();

Notes

Code of WC_AJAX::json_search_downloadable_products_and_variations() WC 5.9.0

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 );
}