问题概述
将Mollie Payments for WooCommerce与 WPML 配合使用时,您可能会遇到以下问题:您在WPML字符串翻译中翻译的付款方式标题和说明,会在次要语言的结账页面上以默认语言显示(Mollie 8.0 及更高版本)。
临时解决方法
将此代码添加到您主题的 functions.php 文件中。它会翻译标题和区块结账说明;经典结账页面上的说明没有临时解决方法:
PHP
$wpml_mollie_text = function ( $incoming, $gateway_id, $key ) {
if ( 0 !== strpos( (string) $gateway_id, 'mollie_wc_gateway_' ) ) { return $incoming; }
$settings = get_option( $gateway_id . '_settings', [] );
$original = is_array( $settings ) ? ( $settings[ $key ] ?? '' ) : '';
if ( ! is_string( $original ) || '' === $original ) { return $incoming; }
$t = apply_filters( 'wpml_translate_single_string', $original, 'admin_texts_woocommerce_gateways', $gateway_id . '_gateway_' . $key, apply_filters( 'wpml_current_language', null ) );
return is_string( $t ) && $t !== $original ? $t : $incoming;
};
add_filter( 'woocommerce_gateway_title', function ( $v, $id = '' ) use ( $wpml_mollie_text ) { return $wpml_mollie_text( $v, $id, 'title' ); }, 20, 2 );
add_filter( 'woocommerce_gateway_description', function ( $v, $id = '' ) use ( $wpml_mollie_text ) { return $wpml_mollie_text( $v, $id, 'description' ); }, 20, 2 );
add_filter( 'inpsyde_payment_gateway_blocks_data', function ( $data, $id, $gateway ) use ( $wpml_mollie_text ) {
if ( isset( $data['content'] ) && is_string( $data['content'] ) ) { $data['content'] = $wpml_mollie_text( $data['content'], $id, 'description' ); }
return $data;
}, 20, 3 );