首页 > 解决方案 > 如何本地化 Woocommerce 权重

问题描述

因此,在 Woocommerce 重量和其他俄语度量系统的设置中。但在产品页面中,例如它仍然是英文(g - gramm)。我已将文件复制到我的主题中:/wp-content/themes/my_theme/woocommerce/single-product/product-attributes.php 我应该在此文件中做什么才能以俄语显示正确的体重度量系统?这段代码没有帮助:

<td class="product_weight"><?php echo wc_format_localized_decimal( $product->get_weight() ) . ' ' . __(esc_attr( get_option( 'woocommerce_weight_unit' ) ), 'woocommerce'); ?></td>

代码/product-attributes.php

defined( 'ABSPATH' ) || exit;

if ( ! $product_attributes ) {
    return;
}
?>
<table class="woocommerce-product-attributes shop_attributes">
    <?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
        <tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
            <th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
            <td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
        </tr>
    <?php endforeach; ?>
</table>

谢谢!

标签: phpwordpresswoocommerce

解决方案


完成,刚刚在主题的functions.php中发布了这段代码

function localize_weight_units($weight) {
    return str_replace('g', 'г', $weight);
}
add_filter('woocommerce_format_weight', 'localize_weight_units');

推荐阅读