• Hi, there,

    Does anybody know how to solve this issue?

    When I add a product with variations to the basket in WooCommerce, it shows the title of the product correctly but the variation is shown in both languages, including the codes [:es]texto[:en]Text[:], like in this example, where the variation is the license type:

    Floral Pattern Garden Roses – [:es]Comercial[:en]Commercial[:]

    I would really appreciate some help with this as I cannot find anywhere a solution.
    Thanks in advance

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Have the same trouble. No fix for now

    I fixed this by creating a filter in my themes function.php. I just didn’t have the time (yet) to dig in deep enough to into both WP multilang and Woocommerce to figure out what needed to be be identified at filter level to get the attribute names translated correctly. With my tests this now works.

    add_filter( 'woocommerce_cart_item_name', 'cart_variation_description', 20, 3);
    function cart_variation_description( $title, $cart_item, $cart_item_key ) {
        $item = $cart_item['data'];
        $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    
        if(!empty($item) && $item->is_type( 'variation' ) ) {
            $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->ge$
            $translate_name = translate_title($item->get_name());
            return sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), wpm_translate_string($translate_name));
        } else
            return sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $title);
    }
    
    function translate_title($title) {
        $all_matches = array();
        preg_match_all("/[^\[\]]*/", $title, $all_matches);
        $matches = $all_matches[0];
        $lang_string = "";
        $user_language = wpm_get_language();
        $output_string = "%s[:%s]%s[:]";
    
        $i = 0;
        $size = count($matches);
        while ($i < $size) {
            $val = $matches[$i];
            if (strlen($val) == 0) {
                $i++;
                continue;
            }
            if (strpos($val, ':') === 0) {
                if (strpos($val, $user_language) >= 1) {
                    $lang_string = sprintf($output_string, $lang_string, $user_language, $matches[$i + 2]);
                }
                $i += 3;
            } else if (strlen($val) > 1) {
                $lang_string = sprintf($output_string, $lang_string, $user_language, $val);
                $i++;
            }
        }
        return $lang_string;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WooCommerce- Issues with products included in the cart’ is closed to new replies.