Automattic\WooCommerce\StoreApi\Schemas\V1
CartItemSchema::format_variation_data()
Format variation data, for example convert slugs such as attribute_pa_size to Size.
Метод класса: CartItemSchema{}
Хуки из метода
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->format_variation_data( $variation_data, $product );
- $variation_data(массив) (обязательный)
- Array of data from the cart.
- $product(\WC_Product) (обязательный)
- Product data.
Код CartItemSchema::format_variation_data() CartItemSchema::format variation data WC 7.5.0
protected function format_variation_data( $variation_data, $product ) { $return = []; if ( ! is_iterable( $variation_data ) ) { return $return; } foreach ( $variation_data as $key => $value ) { $taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $key ) ) ); if ( taxonomy_exists( $taxonomy ) ) { // If this is a term slug, get the term's nice name. $term = get_term_by( 'slug', $value, $taxonomy ); if ( ! is_wp_error( $term ) && $term && $term->name ) { $value = $term->name; } $label = wc_attribute_label( $taxonomy ); } else { /** * Filters the variation option name. * * Filters the variation option name for custom option slugs. * * @internal Matches filter name in WooCommerce core. * * @param string $value The name to display. * @param null $unused Unused because this is not a variation taxonomy. * @param string $taxonomy Taxonomy or product attribute name. * @param \WC_Product $product Product data. * @return string */ $value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product ); $label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product ); } $return[] = [ 'attribute' => $this->prepare_html_response( $label ), 'value' => $this->prepare_html_response( $value ), ]; } return $return; }