问题概述
当将 Deposits & Partial Payments for WooCommerce 与 WPML 一起使用时,您可能会遇到以下问题:翻译后的产品无法获取产品自身的定金设置,并且“已收到定金付款”电子邮件会以默认语言发送给客户。
临时解决方法
前往 WPML设置 并将以下内容添加到自定义 XML 配置中:
<custom-fields>
<custom-field action="copy">_awcdp_deposit_enabled</custom-field>
<custom-field action="copy">_awcdp_deposit_type</custom-field>
<custom-field action="copy">_awcdp_deposits_deposit_amount</custom-field>
</custom-fields>
<admin-texts>
<key name="woocommerce_awcdp_deposit_paid_settings">
<key name="subject" />
<key name="heading" />
<key name="email_text" />
<key name="payment_text" />
</key>
</admin-texts>然后在 WPML字符串翻译 中翻译电子邮件文本,并将以下代码添加到子主题的 functions.php 文件中,以便电子邮件文本和付款文本使用订单语言:
PHP
add_filter( 'woocommerce_email_get_option', function ( $value, $email, $old, $key ) {
if ( 'awcdp_deposit_paid' !== $email->id || ! in_array( $key, [ 'email_text', 'payment_text' ], true ) ) {
return $value;
}
if ( empty( $email->object ) || ! is_a( $email->object, 'WC_Order' ) ) {
return $value;
}
$lang = $email->object->get_meta( 'wpml_language', true );
if ( ! $lang ) {
return $value;
}
return apply_filters(
'wpml_translate_single_string',
$value,
'admin_texts_woocommerce_awcdp_deposit_paid_settings',
'[woocommerce_awcdp_deposit_paid_settings]' . $key,
$lang
);
}, 20, 4 );