问题概述
将YITH WooCommerce Request a Quote与 WPML 结合使用时,您可能会遇到以下问题:以一种语言添加到报价列表中的产品,在访客切换语言后仍会保留该语言的名称,并且以另一种语言添加相同产品时会添加第二行。
免费插件在 2.56.1 版本中修复了此问题。高级插件尚未包含此修复(已在 4.48.0 版本中测试)。
临时解决方法
将此代码添加到您主题的 functions.php 文件中。它以当前语言显示报价列表中的每个产品,并合并同一产品的行:
PHP
add_action( 'wp', function () {
if ( ! function_exists( 'YITH_Request_Quote' ) ) { return; }
$q = YITH_Request_Quote();
$lang = apply_filters( 'wpml_current_language', null );
$list = [];
foreach ( (array) $q->raq_content as $item ) {
$pid = (int) apply_filters( 'wpml_object_id', (int) $item['product_id'], 'product', true, $lang );
$vid = empty( $item['variation_id'] ) ? '' : (int) apply_filters( 'wpml_object_id', (int) $item['variation_id'], 'product_variation', true, $lang );
$key = md5( $pid . $vid );
$item['product_id'] = $pid;
if ( '' !== $vid ) { $item['variation_id'] = $vid; }
if ( isset( $list[ $key ] ) ) { $list[ $key ]['quantity'] += (int) $item['quantity']; } else { $list[ $key ] = $item; }
}
$q->raq_content = $list;
$q->set_session( $list, true );
}, 98 );