WC_REST_Products_V2_Controller::get_default_attributes()
Get default attributes.
Method of the class: WC_REST_Products_V2_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_V2_Controller::get_default_attributes() WC REST Products V2 Controller::get default attributes code WC 7.7.0
protected function get_default_attributes( $product ) { $default = array(); if ( $product->is_type( '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_name( $key, $product ), 'option' => $value, ); } else { $default[] = array( 'id' => 0, 'name' => $this->get_attribute_taxonomy_name( $key, $product ), 'option' => $value, ); } } } return $default; }