我正在使用woocommerce + wpml,我想以编程方式设置完成的电子邮件订单。 我正在尝试使用$ sitepress-> switch_lang(),但似乎无效。
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed' );
function mysite_woocommerce_order_status_completed($order_id)
{
global $sitepress;
$sitepress->switch_lang('en', true);
if($sitepress->get_current_language() == 'en')
{
$mailer = WC()->mailer();
$recipient = 'customer@mail.com';
$subject = 'Your Order has been completed';
$content = get_processing_notification_content_completed( $order, $subject, $mailer );
$headers = "Content-Type: text/html\r\n";
$mailer->send( $recipient, $subject, $content, $headers );
}
}
function get_processing_notification_content_completed( $order, $heading = false, $mailer ) {
$template = 'emails/customer-completed-order.php';
return wc_get_template_html( $template, array(
'order' => $order,
'email_heading' => $heading,
'sent_to_admin' => true,
'plain_text' => false,
'email' => $mailer
) );
}
虽然我使用“switch_lang()”,但邮件继续以意大利语显示。