Automattic\WooCommerce\Admin\API

ProductAttributes::get_items()publicWC 1.0

Get all attributes, with support for searching (which includes custom attributes).

Method of the class: ProductAttributes{}

No Hooks.

Return

WP_REST_Response.

Usage

$ProductAttributes = new ProductAttributes();
$ProductAttributes->get_items( $request );
$request(WP_REST_Request) (required)
The API request.

ProductAttributes::get_items() code WC 8.6.1

public function get_items( $request ) {
	if ( empty( $request['search'] ) ) {
		return parent::get_items( $request );
	}

	$search_string       = $request['search'];
	$custom_attributes   = $this->get_custom_attributes( array( 'name' => $search_string ) );
	$matching_attributes = $this->format_custom_attribute_items_for_response( $custom_attributes );
	$taxonomy_attributes = wc_get_attribute_taxonomies();

	foreach ( $taxonomy_attributes as $attribute_obj ) {
		// Skip taxonomy attributes that didn't match the query.
		if ( false === stripos( $attribute_obj->attribute_label, $search_string ) ) {
			continue;
		}

		$attribute             = $this->prepare_item_for_response( $attribute_obj, $request );
		$matching_attributes[] = $this->prepare_response_for_collection( $attribute );
	}

	$response = rest_ensure_response( $matching_attributes );
	$response->header( 'X-WP-Total', count( $matching_attributes ) );
	$response->header( 'X-WP-TotalPages', 1 );

	return $response;
}