好吧,对于那些后来偶然发现这个问题的人,这里有一个更完整的答案。
add_filter( \'woocommerce_checkout_fields\' , \'custom_override_checkout_fields\' );
function custom_override_checkout_fields( $fields ) {
$fields[\'order\'][\'language\'][\'placeholder\'] = \'\';
$fields[\'order\'][\'language\'][\'type\'] = \'text\';
$fields[\'order\'][\'language\'][\'label\'] = \'language\';
$fields[\'order\'][\'language\'][\'class\'] = array(\'hidden\');
$fields[\'order\'][\'language\'][\'default\'] = qtrans_getLanguage();
return $fields;
}
然后。。。您需要在签出时保存该字段,这很简单:
/**
* Save the language to the order (despite what woocommerce doc says this is required)
*/
add_action( \'woocommerce_checkout_update_order_meta\', \'my_custom_checkout_field_update_order_meta\' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[\'language\'] ) ) {
update_post_meta( $order_id, \'language\', sanitize_text_field( $_POST[\'language\'] ) );
}
}
然后。。。(这部分有点老套,但我从电子邮件创建的开始(主题)开始,然后将语言更改为订单的语言)。我不认为您真的需要担心更改回它,因为一旦线程死亡,它将切换回默认状态。它应该在发送完这封邮件后立即消失,因为这只会在回拨时发生。
add_filter(\'woocommerce_email_subject_customer_completed_order\', \'waspdigital_order_complete_language_fix\', 1, 2);
function waspdigital_order_complete_language_fix( $subject, $order ){
global $woocommerce;
$new_locale = get_post_meta( $order->id, \'language\', true);
// set the current locale and send email with it active
unload_textdomain(\'woocommerce\');
setlocale(LC_ALL, $new_locale);
global $q_config, $locale, $woocommerce;
$locale = $new_locale;
$q_config[\'language\'] = substr($new_locale, 0, 2);
$woocommerce->load_plugin_textdomain();
/*
// set the old locale back
unload_textdomain(\'woocommerce\');
$q_config[\'language\'] = substr($old_locale, 0, 2);
$locale = $old_locale;
setlocale(LC_ALL, $old_locale);
$woocommerce->load_plugin_textdomain();
*/
return $subject;
}