WordPress at Your Fingertips
function is not described

WC_REST_Products_V1_Controller::get_attributes() protected WC 1.0

Get the attributes for a product or product variation.

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

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_attributes( $product );
$product(WC_Product|WC_Product_Variation) (required)
Product instance.

Code of WC_REST_Products_V1_Controller::get_attributes() WC 5.9.0

protected function get_attributes( $product ) {
	$attributes = array();

	if ( $product->is_type( 'variation' ) ) {
		// Variation attributes.
		foreach ( $product->get_variation_attributes() as $attribute_name => $attribute ) {
			$name = str_replace( 'attribute_', '', $attribute_name );

			if ( ! $attribute ) {
				continue;
			}

			// Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
			if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) {
				$option_term = get_term_by( 'slug', $attribute, $name );
				$attributes[] = array(
					'id'     => wc_attribute_taxonomy_id_by_name( $name ),
					'name'   => $this->get_attribute_taxonomy_label( $name ),
					'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute,
				);
			} else {
				$attributes[] = array(
					'id'     => 0,
					'name'   => $name,
					'option' => $attribute,
				);
			}
		}
	} else {
		foreach ( $product->get_attributes() as $attribute ) {
			if ( $attribute['is_taxonomy'] ) {
				$attributes[] = array(
					'id'        => wc_attribute_taxonomy_id_by_name( $attribute['name'] ),
					'name'      => $this->get_attribute_taxonomy_label( $attribute['name'] ),
					'position'  => (int) $attribute['position'],
					'visible'   => (bool) $attribute['is_visible'],
					'variation' => (bool) $attribute['is_variation'],
					'options'   => $this->get_attribute_options( $product->get_id(), $attribute ),
				);
			} else {
				$attributes[] = array(
					'id'        => 0,
					'name'      => $attribute['name'],
					'position'  => (int) $attribute['position'],
					'visible'   => (bool) $attribute['is_visible'],
					'variation' => (bool) $attribute['is_variation'],
					'options'   => $this->get_attribute_options( $product->get_id(), $attribute ),
				);
			}
		}
	}

	return $attributes;
}