src/Hyyan/WPI/Cart.php
/**
     * Translate displayed product in cart.
     *
     * @param \WC_Product|\WC_Product_Variation $cart_item_data
     * @param array                             $cart_item
     *
     * @return \WC_Product|\WC_Product_Variation
     */
Translate displayed product in cart.


Translate displayed product in cart .
public function translateCartItemProduct($cart_item_data, $cart_item)
    {
        $cart_product_id   = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
        $cart_variation_id = isset($cart_item['variation_id']) ? $cart_item['variation_id'] : 0;
        $cart_item_data_translation = $cart_item_data;
        switch ($cart_item_data->get_type()) {
            case 'variation':
                $variation_translation   = $this->getVariationTranslation($cart_variation_id);
                if ( $variation_translation && $variation_translation->get_id() != $cart_variation_id ) {
                  $cart_item_data_translation = $variation_translation;
                }
                break;
            case 'simple':
            default:
                $product_translation        = Utilities::getProductTranslationByID($cart_product_id);
                if ( $product_translation && $product_translation->get_id() != $cart_product_id ) {
                  $cart_item_data_translation = $product_translation;
                }
                break;
        }
        if ( $cart_item_data_translation->get_id() != $cart_item_data->get_id() ) {
            $cart_item_data_translation = apply_filters( HooksInterface::CART_SWITCHED_ITEM, $cart_item_data_translation, $cart_item_data, $cart_item );
        }
        return $cart_item_data_translation;
    }
public function translateCartItemProduct ( $ cart_item_data , $ cart_item ) { $ cart_product_id = isset ( $ cart_item [ 'product_id' ] ) ? $ cart_item [ 'product_id' ] : 0 ; $ cart_variation_id = isset ( $ cart_item [ 'variation_id' ] ) ? $ cart_item [ 'variation_id' ] : 0 ; $ cart_item_data_translation = $ cart_item_data ; switch ( $ cart_item_data -> get_type ( ) ) { case 'variation' : $ variation_translation = $ this -> getVariationTranslation ( $ cart_variation_id ) ; if ( $ variation_translation && $ variation_translation -> get_id ( ) != $ cart_variation_id ) { $ cart_item_data_translation = $ variation_translation ; } break ; case 'simple' : default : $ product_translation = Utilities :: getProductTranslationByID ( $ cart_product_id ) ; if ( $ product_translation && $ product_translation -> get_id ( ) != $ cart_product_id ) { $ cart_item_data_translation = $ product_translation ; } break ; } if ( $ cart_item_data_translation -> get_id ( ) != $ cart_item_data -> get_id ( ) ) { $ cart_item_data_translation = apply_filters ( HooksInterface :: CART_SWITCHED_ITEM , $ cart_item_data_translation , $ cart_item_data , $ cart_item ) ; } return $ cart_item_data_translation ; }
Translate displayed product in cart.
Translate displayed product in cart .
// By default, returns the same input // If we are changing the product to the right language