src/Hyyan/WPI/Cart.php
/**
     * Translate product variation attributes.
     *
     * @param array     $item_data      Variation attributes
     * @param array     $cart_item      Cart item
     *
     * @return array   Translated attributes
     */
Translate product variation attributes.
@param array     $item_data      Variation attributes
@param array     $cart_item      Cart item

@return array   Translated attributes
Translate product variation attributes . @param array $item_data Variation attributes @param array $cart_item Cart item @return array Translated attributes
public function translateCartItemData($item_data, $cart_item)
    {
        $cart_variation_id = isset($cart_item['variation_id']) ? $cart_item['variation_id'] : 0;
        if ($cart_variation_id == 0) {
            return $item_data;
        } elseif ($cart_variation_id != 0  && false == $this->getVariationTranslation($cart_variation_id)) {
            return $item_data;
        }
        $item_data_translation = array();
        foreach ($item_data as $data) {
            $term_id = null;
            foreach ($cart_item['variation'] as $tax => $term_slug) {
                $tax  = str_replace('attribute_', '', $tax);
                $term = get_term_by('slug', $term_slug, $tax);
                if ($term && $term->name === $data['value']) {
                    $term_id = $term->term_id;
                    break;
                }
            }
            if ($term_id !== 0 && $term_id !== null) {
                $term_id_translation = pll_get_term($term_id);
                if ($term_id_translation == $term_id) {
                    $item_data_translation[] = $data;
                } else {
                    $term_translation = get_term($term_id_translation);
                    $error = get_class($term_translation) == 'WP_Error';
                    $item_data_translation[] = array('key' => $data['key'], 'value' => !$error ? $term_translation->name : $data['value'] ); 
                }
            } else {
                $item_data_translation[] = $data;
            }
        }
        return !empty($item_data_translation) ? $item_data_translation : $item_data;
    }
public function translateCartItemData ( $ item_data , $ cart_item ) { $ cart_variation_id = isset ( $ cart_item [ 'variation_id' ] ) ? $ cart_item [ 'variation_id' ] : 0 ; if ( $ cart_variation_id == 0 ) { return $ item_data ; } elseif ( $ cart_variation_id != 0 && false == $ this -> getVariationTranslation ( $ cart_variation_id ) ) { return $ item_data ; } $ item_data_translation = array ( ) ; foreach ( $ item_data as $ data ) { $ term_id = null ; foreach ( $ cart_item [ 'variation' ] as $ tax => $ term_slug ) { $ tax = str_replace ( 'attribute_' , '' , $ tax ) ; $ term = get_term_by ( 'slug' , $ term_slug , $ tax ) ; if ( $ term && $ term -> name === $ data [ 'value' ] ) { $ term_id = $ term -> term_id ; break ; } } if ( $ term_id !== 0 && $ term_id !== null ) { $ term_id_translation = pll_get_term ( $ term_id ) ; if ( $ term_id_translation == $ term_id ) { $ item_data_translation [ ] = $ data ; } else { $ term_translation = get_term ( $ term_id_translation ) ; $ error = get_class ( $ term_translation ) == 'WP_Error' ; $ item_data_translation [ ] = array ( 'key' => $ data [ 'key' ] , 'value' => ! $ error ? $ term_translation -> name : $ data [ 'value' ] ) ; } } else { $ item_data_translation [ ] = $ data ; } } return ! empty ( $ item_data_translation ) ? $ item_data_translation : $ item_data ; }
Translate product variation attributes.
Translate product variation attributes .
// We don't translate the variation attributes if the product in the cart // is not a product variation, and in case of a product variation, it // doesn't have a translation in the current language. // Not a variation product // Variation product without translation in current language // Product attribute is a taxonomy term - check if Polylang has a translation // Already showing the attribute (term) in the correct language // Get term translation from id // On error return same // Product attribute is post metadata and not translatable - return same