Reputation: 1
I found a good code here to create a unique order status with the option to send an email. It works well, the only problem is that my website is bilingual (ro,hu) and all unique status emails are sent translated in the default language (ro), and it does not take into account if the customer just bought in hu. How can I insert this into the code so that if I send the email to a Hungarian, the translator does not translate it, but if the customer ordered in ro, it does?
I already asked the AI, I tried several codes, but none of them work.
I tried thr following code attemps:
add_action('woocommerce_email_order_meta', function($order) {
global $wpdb;
$order_id = $order->get_id();
$order_language = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM ls_wc_orders_meta WHERE order_id = %d AND meta_key = 'trp_language'",$order_id));
if ($order_language) {
add_filter('locale', function($locale) use ($order_language) {
return $order_language;});
if (function_exists('trp_change_language')) {
trp_change_language($order_language);
}
}, 10, 1);
add_filter( 'gettext', 'remove_translate_for_custom_email', 10, 3 );
function remove_translate_for_custom_email( $translated_text, $text, $domain ) {
if ( $domain === 'woocommerce' ) {
return $text;
}
return $translated_text;
}
add_action( 'woocommerce_email_before_order_table', 'set_email_language', 10, 4 );
function set_email_language( $order, $sent_to_admin, $plain_text, $email ) {
switch_to_locale( 'en_US' );
}
add_action( 'woocommerce_email_after_order_table', 'reset_email_language', 10, 1 );
function reset_email_language( $order ) {
restore_previous_locale();
}
But none of them worked, and I can't figure out if I'm trying to use the wrong hook or if the problem is elsewhere.
Upvotes: 0
Views: 211