最佳答案
尝试以下代码来更改前端显示的尺寸单位:
add_filter( 'woocommerce_format_dimensions', 'custom_dimention_unit', 20, 2 );
function custom_dimention_unit( $dimension_string, $dimensions ){
$dimension_string = implode( ' x ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );
if ( ! empty( $dimension_string ) ) {
$dimension_string .= ' ' . __('ft');
} else {
$dimension_string = __( 'N/A', 'woocommerce' );
}
return $dimension_string;
}
代码位于事件子主题(或事件主题)的 function.php 文件中。
更新:全局(任何地方)使用尺寸单位“ft”(英尺)
Woocommerce 尺寸可用单位为“米”、“厘米”、“毫米”、“英寸”和“码”。
But "ft" is not available in the Woocommerce > Settings > Products > Mesurements section.
您可以执行以下操作:
将以下行粘贴到您的 function.php 文件中并保存:
update_option( 'woocommerce_dimension_unit', 'ft' );
浏览您网站的任何页面。
从 function.php 文件中删除或注释该代码行并保存。
您还可以删除第一个代码片段,因为它不再需要了。
你已经完成了。
你会得到类似的东西:
在后端:
For info, to change the dimensions unit in Woocommerce > Settings > Products:
关于php - 如何在 Woocommerce 3 中设置不存在的尺寸测量单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51304704/