問題の概要
WPMLでDeposits & Partial Payments for WooCommerceを使用すると、翻訳された商品に商品独自のデポジット設定が適用されない問題や、「デポジット支払い受領」メールがデフォルト言語で顧客に届く問題が発生する場合があります。
回避策
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 );