【发布时间】:2018-07-08 08:33:16
【问题描述】:
首先,我要感谢 LoicTheAztec 的回答 here。我正在寻找非常相似的定制,但不是 100% 相同,我想要实现的是:WxLxHmm
是的,最后是计量单位。
示例: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);
}
【问题讨论】:
标签: php wordpress woocommerce product dimensions