WC_REST_Products_V1_Controller::get_default_attributes()
Get default attributes.
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_default_attributes( $product );
- $product(WC_Product) (required)
- Product instance.
WC_REST_Products_V1_Controller::get_default_attributes() WC REST Products V1 Controller::get default attributes code WC 9.8.1
protected function get_default_attributes( $product ) { $default = array(); if ( $product->is_type( ProductType::VARIABLE ) ) { foreach ( array_filter( (array) $product->get_default_attributes(), 'strlen' ) as $key => $value ) { if ( 0 === strpos( $key, 'pa_' ) ) { $default[] = array( 'id' => wc_attribute_taxonomy_id_by_name( $key ), 'name' => $this->get_attribute_taxonomy_label( $key ), 'option' => $value, ); } else { $default[] = array( 'id' => 0, 'name' => wc_attribute_taxonomy_slug( $key ), 'option' => $value, ); } } } return $default; }