WC_REST_Product_Attributes_V1_Controller::get_attribute()protectedWC 1.0

Get attribute data.

Method of the class: WC_REST_Product_Attributes_V1_Controller{}

No Hooks.

Return

stdClass|WP_Error.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_attribute( $id );
$id(int) (required)
Attribute ID.

WC_REST_Product_Attributes_V1_Controller::get_attribute() code WC 8.6.1

protected function get_attribute( $id ) {
	global $wpdb;

	$attribute = $wpdb->get_row(
		$wpdb->prepare(
			"
		SELECT *
		FROM {$wpdb->prefix}woocommerce_attribute_taxonomies
		WHERE attribute_id = %d
	 ",
			$id
		)
	);

	if ( is_wp_error( $attribute ) || is_null( $attribute ) ) {
		return new WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	return $attribute;
}