How to translate mail from Photo Reviews for WooCommerce

Works since version 1.2.7 of Photo Reviews for WooCommerce

use Weglot\Parser\Parser;
use Weglot\Parser\ConfigProvider\ServerConfigProvider;

function wg_viwcpr_email_reminder_get_content( $content, $order_id ){ 
	global $woocommerce, $post;
	
    	$option_services   = weglot_get_service( 'Option_Service_Weglot' );
	$parser_services   = weglot_get_service( 'Parser_Service_Weglot' );
	$language_services = weglot_get_service( 'Language_Service_Weglot' );
	$original_language = $language_services->get_original_language()->getInternalCode();

	$woocommerce_order_language = get_post_meta( $order_id, 'weglot_language', true ); // phpcs:ignore
	
	if ( $woocommerce_order_language == weglot_get_original_language() ) {
		return $content;
	}
	
	$config             = new ServerConfigProvider();
	$client             = $parser_services->get_client();
	$parser             = new Parser( $client, $config, [] );
	$content = $parser->translate( $content, $original_language, $woocommerce_order_language ); //phpcs:ignore
   
    return $content;
} 

function viwcpr_email_reminder_get_subject( $subject, $order_id ){ 
	global $woocommerce, $post;
	
    $option_services   = weglot_get_service( 'Option_Service_Weglot' );
	$parser_services   = weglot_get_service( 'Parser_Service_Weglot' );
	$language_services = weglot_get_service( 'Language_Service_Weglot' );
	$original_language = $language_services->get_original_language()->getInternalCode();

	$woocommerce_order_language = get_post_meta( $order_id, 'weglot_language', true ); // phpcs:ignore
	
	if ( $woocommerce_order_language == weglot_get_original_language() ) {
		return $content;
	}
	
	$config             = new ServerConfigProvider();
	$client             = $parser_services->get_client();
	$parser             = new Parser( $client, $config, [] );
	$subject = $parser->translate( $subject, $original_language, $woocommerce_order_language ); //phpcs:ignore
   
    return $subject;
} 

//add the action 
add_filter('viwcpr_email_reminder_get_content', 'wg_viwcpr_email_reminder_get_content', 10, 2);
add_filter('viwcpr_email_reminder_get_subject', 'viwcpr_email_reminder_get_subject', 10, 2);

Last updated