• Resolved moultrex

    (@moultrex)


    Hello.

    There is a problem with Variable Products in cart page.

    Lets say we have a product with the title:

    Shoes Collection 2019

    If we translate the product title to a different language it is working fine.

    But if we choose in the translated product page a color/size and add this product in cart, on the woocommerce cart page the product title is reverted back to default language because woocommerce shows additional text based on the variation choice we have done.

    For example on cart page we will see something like

    Shoes Collection 2019 – Brown, 42

    So although we are on the translated page the Shoes Collection 2019 part is not translated cause woocommerce added the additional – Brown, 42 text and translatepress thinks this is a different text altogether.

    We can’t translate every possible compination.

    Can you fix it please.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Georgian Cocora

    (@raster02)

    Hello @moultrex,

    Please add the following code snippet to your website:

    add_filter( 'woocommerce_product_variation_title', 'trpc_woo_wrap_variation', 10, 4 );
    function trpc_woo_wrap_variation( $name, $product, $title_base, $title_suffix ){
       $separator  = '<span> - </span>';
       
       return $title_suffix ? $title_base . $separator . $title_suffix : $title_base;
    }

    Afterwards, the translation for the first part of the string should remain as you added it and you only need to translate the variation name like Color.

    Let me know if this worked.

    Regards.

    Thread Starter moultrex

    (@moultrex)

    @raster02

    Yeah it kinda works.

    For example, we have products that their title is:

    Leather Jacket – Collection Winter

    and other products that their title is:

    Leather Jacket

    On the first product the string is not translated because your snippet finds the first ‘ – ‘ that is part of the product title.

    The second product it gets translated though because there is not a ‘ – ‘ in the title.

    Is there a way to not check the product title for ‘ – ‘ so it can work on all products?

    Thank you.

    Thread Starter moultrex

    (@moultrex)

    I tried a different way and still doesn’t work.

    So for example.

    I have a product.

    Shirt – Collection Spring / Summer

    I translate it

    and then from your code i just return the $title_base

    So the code is:

    add_filter( 'woocommerce_product_variation_title', 'trpc_woo_wrap_variation', 10, 4 );
    function trpc_woo_wrap_variation( $name, $product, $title_base, $title_suffix ){
      
       
       return $title_base;
    }

    Now at the cart after the product’s translated name

    Shirt – Collection Spring / Summer

    there is NO – size , Color etc.

    BUT still it doesn’t get translated

    Only if i remove the – from the product title and become like

    Shirt Collection Spring / Summer

    only then it get’s translated.

    Why is that?

    • This reply was modified 5 years, 11 months ago by moultrex.
    • This reply was modified 5 years, 11 months ago by moultrex.
    Thread Starter moultrex

    (@moultrex)

    Edit.

    Wow i couldn’t believe my eyes.

    Wordpress use the filter wptexturize and was converting

    Leather Jacket – Collection Winter the single dash to a ndash (double dash)

    That’s why when i translated a product title, it translated the double dash and at the cart page the single dash was outputing.

    I disabled the filter with these filters

    remove_filter( ‘the_title’, ‘wptexturize’ );
    remove_filter( ‘the_content’, ‘wptexturize’ );
    remove_filter( ‘the_excerpt’, ‘wptexturize’ );

    and now at the cart page the right translation is showing.

    Thank you very much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Variable Product in Cart Problem’ is closed to new replies.