问题概述
将WP Configurator Pro与 WPML 结合使用时,您可能会遇到以下问题:在链接到配置器的已翻译 WooCommerce 产品中,配置器标题会替换产品标题,配置器说明保持为英语,并且 PDF 文本无法翻译。
临时解决方法
将以下代码添加到子主题的functions.php文件中:
PHP
add_filter( 'the_title', function ( $title, $id = 0 ) {
if ( ( is_admin() && ! wp_doing_ajax() ) || ! $id || 'product' !== get_post_type( $id ) ) {
return $title;
}
$post = get_post( $id );
return $post ? $post->post_title : $title;
}, 11, 2 );
add_filter( 'do_shortcode_tag', function ( $out, $tag, $attr ) {
if ( 'wpc_config_description' !== $tag || empty( $attr['id'] ) ) {
return $out;
}
$id = absint( $attr['id'] );
return wp_kses_post( apply_filters( 'wpc_single_product_description', get_post_meta( $id, '_wpc_description', true ), $id ) );
}, 10, 3 );前往WPML设置,并将以下内容添加到自定义 XML 配置中:
XML
<wpml-config>
<admin-texts>
<key name="wpc_pdf_document_heading" />
<key name="wpc_pdf_download_btn_text" />
</admin-texts>
</wpml-config>然后在WPML字符串翻译中翻译这些文本。