Reorder and customize product dimensions formatted output in WooCommerce

旧街凉风 提交于 2019-12-01 13:52:56

To re-order dimensions output in a different way customization on your code that you need is:

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' );
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works.

This will output something like 200x600x200mm (with mm at the end just once).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!