php - 如何本地化 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>
谢谢!
解决方案
完成,刚刚在主题的functions.php中发布了这段代码
function localize_weight_units($weight) {
return str_replace('g', 'г', $weight);
}
add_filter('woocommerce_format_weight', 'localize_weight_units');
推荐阅读
- html - Bootstrap 4:文本居中和左对齐?
- powerbi - 如何在 Power BI 中的页面级别限制日历表
- c - xmlUnlinkNode 未从 xml 文件中删除子节点
- c - 从 glib/gtk 中的单独线程发出信号
- r - 计算每行的分位数后如何选择行?
- python - RabbitMQ - Python/Pika 如何知道队列是否为空?
- android - 如何在检索数据时访问 firebase 中的未知节点?
- angular - How can I show my own text status before i switch my toggle button while using mat-slide-toggle
- django-models - django模型一对多保存失败
- javascript - Typescript Jest 测试中来自 ol-ext 的“SyntaxError: Unexpected identifier”