首先,我要感谢LoicTheAztec在这里的回答。我正在寻找非常相似的自定义,但并非100%相同,我想要实现的是:W
x L
x H
mm
是的,最后一个计量单位。
范例:200x600x200mm
提供答案后,我设法获得了200mmx600mmx200mm
如果我只想在末尾使用单位“ mm”,该怎么办?
下面是我的编辑代码版本
add_filter( 'woocommerce_format_dimensions', 'custom_formated_product_dimensions', 10, 2 );
function custom_formated_product_dimensions( $dimension_string, $dimensions ){
if ( empty( $dimension_string ) )
return __( 'N/A', 'woocommerce' );
// Set here your new array of dimensions based on existing keys/values
$new_dimensions = array(
'width' => $dimensions['width'],
'length' => $dimensions['length'],
'height' => $dimensions['height']
);
$dimensions = array_filter( array_map( 'wc_format_localized_decimal', $new_dimensions ) );
foreach( $dimensions as $key => $dimension ){
$label_with_dimensions[$key] = $dimension . '' . get_option( 'woocommerce_dimension_unit' ). '';
}
return implode( 'x', $label_with_dimensions);
}
要以其他方式对维度输出进行重新排序,您需要对代码进行自定义:
add_filter( 'woocommerce_format_dimensions', 'custom_formated_product_dimentions', 10, 2 );
function custom_formated_product_dimentions( $dimension_string, $dimensions ){
if ( empty( $dimension_string ) )
return __( 'N/A', 'woocommerce' );
// Set here your new reordered array of dimensions based on existing keys/values
$new_dimentions = array(
'width' => $dimensions['width'],
'length' => $dimensions['length'],
'height' => $dimensions['height']
);
$dimensions = array_filter( array_map( 'wc_format_localized_decimal', $new_dimentions ) );
return implode( 'x', $dimensions) . get_option( 'woocommerce_dimension_unit' );
}
代码进入活动子主题(或活动主题)的function.php文件中。
经过测试和工作。
这将输出类似200x600x200mm
(mm
最后只带一次)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句