Добавление букв W H L к значениям размера товара в Woocommerce
Задача: По-умолчанию размер товара в Woocommerce отображается просто числами, например: “150x240x70”. Надо добавить к числам буквы, обозначающие длину, ширину и высоту, чтобы выглядело так: “L150 x W240 x H70 in”
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' );
$dimensions = array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) );
$label_with_dimensions = []; // Initialising
// Loop Though dimensions array
foreach( $dimensions as $key => $dimention )
$label_with_dimensions[$key] = strtoupper( substr($key, 0, 1) ) . '' . $dimention;
return implode( ' x ', $label_with_dimensions) . ' ' . get_option( 'woocommerce_dimension_unit' );
}
Leave a Reply
You must be logged in to post a comment.