Automattic\WooCommerce\Admin\API
ProductAttributes::get_items
Get all attributes, with support for searching (which includes custom attributes).
Method of the class: ProductAttributes{}
No Hooks.
Returns
WP_REST_Response.
Usage
$ProductAttributes = new ProductAttributes(); $ProductAttributes->get_items( $request );
- $request(WP_REST_Request) (required)
- The API request.
ProductAttributes::get_items() ProductAttributes::get items code WC 10.3.6
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;
}