Site logo

Archived topic

Translate custom values via child theme

5 replies · Started by nik9 on March 23, 2021

Viewing posts 1–6 of 6

Hello,

I use the code snippet below to show some information in checkout when a subscription is added. Work fine. However, I have some problems with the translation. I use Loco Translate to translate plugins etc.

function eg_show_product_removed_message( $url ) {
	global $woocommerce, $eg_set_product_removed_message;

	if ( isset( $eg_set_product_removed_message ) && is_numeric( $eg_set_product_removed_message ) ) {
		wc_add_notice( sprintf( _n( '%s product has been removed from your cart. Products and subscriptions can not be purchased at the same time.', '%s products have been removed from your cart. Products and subscriptions can not be purchased at the same time.', $eg_set_product_removed_message, 'woocommerce-subscriptions' ), $eg_set_product_removed_message ), 'error' );
	}
 
	return $url;
}
add_filter( 'add_to_cart_redirect', 'eg_show_product_removed_message', 11, 1 );

Now, I added the snipped in function.php and want to translate the new added string via loco translate. I use the plugin “woocommerce-subscriptions” to translate that. But this does not work. I already contacted the Loco Translate developer.

His answer:

To do this properly you should either make your code into a plugin with its own text domain, or create a child theme with your custom translations.

Now, how can I translate such stuff via GP child theme? I already use a child theme but have no idea how to use that for translations.

Cheers

Hi there,

you should simply add your function to the child theme functions.php

If its not working then the issue will most likely be related to the text-domain ( currently set to woocommerce-subscriptions ) in your filter. You need to check that is the correct domain.

Hello David,

Yes. woocommerce-subscriptions is 100% right. So I do not understand what he mean with child theme.

cheers

Have you followed up with their support team if you are not clear with their instructions?

You shouldn't need to do anything special with the child theme - the code you've provided can go directly into the function.php file of the child theme.

Hi Leo,

Yes sure. Now I wait for their answer. Very unclear how to get that to work. I mean, this is actually a very common case..

Sounds good.

Their support team should be able to help you out as it's not a theme-specific question.

This archived topic is closed to new replies.