Polylang for WooCommerce, By WP SYNTEX
Use this code to send email using user’s language
1. Please comment out lines 45,46 in file /wp-content/plugins/polylang-wc/include/emails.php
Like
1 2 |
//add_action( 'woocommerce_created_customer', rray( $this, 'created_customer' ), 5 ); // Before WC sends the notification //add_action( 'woocommerce_new_order', array( $this, 'new_order' ) ); |
2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
add_action('woocommerce_before_resend_order_emails', function ($order) { if ( ! function_exists( 'PLLWC' ) || ! function_exists('PLL') ) { return; } if ( is_numeric( $order ) ) { $order_id = $order; } elseif ( is_array( $order ) ) { $order_id = $order['order_id']; } elseif ( is_object( $order ) ) { $order_id = $order->get_id(); } $order = wc_get_order($order_id); if ($order->get_customer_id()) { remove_action('woocommerce_before_resend_order_emails', array( PLLWC()->emails, 'before_order_email' )); remove_filter( 'get_user_metadata', array( PLLWC()->emails, 'filter_user_locale' ), 10, 3 ); $lang = get_user_meta( $order->get_customer_id(), 'locale', true ); $lang = empty( $lang ) ? get_locale() : $lang; add_filter( 'get_user_metadata', array( PLLWC()->emails, 'filter_user_locale' ), 10, 3 ); $language = PLL()->model->get_language( $lang ); remove_filter( 'load_textdomain_mofile', array( PLL()->filters, 'load_textdomain_mofile' ) ); PLLWC()->emails->set_email_language( $language ); add_filter( 'load_textdomain_mofile', array( PLL()->filters, 'load_textdomain_mofile' ) ); } }, 1); |