在WooCommerce中重新排序和自定义产品尺寸格式输出

首先,我要感谢LoicTheAztec在这里的回答我正在寻找非常相似的自定义,但并非100%相同,我想要实现的是:Wx Lx Hmm

是的,最后一个计量单位。

范例: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);
}
LoicTheAztec

要以其他方式对维度输出进行重新排序,您需要对代码进行自定义:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Woocommerce订单格式的账单地址重新排序和自定义账单字段

Woocommerce 中的自定义产品模板和操作挂钩

从产品类别和自定义meta_key对Woocommerce产品进行排序

WooCommerce - 产品变化 - 自定义裁剪尺寸

woocommerce中的自定义产品

通过WP_Query中的自定义Woocommerce产品排序来排序

Woocommerce仅在特定类别和特定页面中向产品添加自定义产品计数

在自定义家庭和产品类别档案中显示WooCommerce产品属性

自定义元值排序在WooCommerce产品中不起作用

如果缺货,则在特定的WooCommerce产品页面中输出自定义代码

在woocommerce电子邮件中输出产品自定义字段(图像)

如何自定义Woocommerce产品页面中的订单数量输出

在 WooCommerce 中输出特定产品类别的自定义短代码

使用WooCommerce和Bootstrap在自定义布局中开发自定义单个产品页面

在WooCommerce格式的产品尺寸输出中包括尺寸字母L / W / H

如何在WooCommerce中为自定义产品类型启用价格和库存

在Woocommerce订单和电子邮件中显示产品变体的自定义字段

从WooCommerce中的变化产品获取自定义字段值和最高价格

在Woocommerce中添加和保存管理产品变体自定义字段

在Woocommerce 3中添加和管理产品自定义上传字段

根据Woocommerce中的运输区域和产品类别显示自定义消息

如何在自定义简码中添加woocommerce分页和woocommerce排序下拉菜单

Excel中框的自定义格式设置尺寸

在WooCommerce产品页面中显示自定义挂钩

Woocommerce 单个产品页面中的自定义内容问题

在WooCommerce中自定义所选产品的变化价格

在Woocommerce产品中动态填充自定义表单

在 Woocommerce 中自定义功能变体产品

结帐中的Woocommerce自定义产品字段