php - Change the Product dimensions order in WooCommerce single product pages -


i'm looking way filter display order or woocommerce product dimensions (length, width, height). i'd display height before width.

at present use custom funtion filter dimensions displayed:

function wsa_show_product_dimensions() {     global $product;     echo $product->list_attributes(); }  add_action( 'woocommerce_single_product_summary', 'wsa_show_product_dimensions', 25 ); 

i've modified product-attributes.php template in order format html that's returned:

<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>     <div class="c-details-row">         <div class="c-details-col c-details-col_1">           <span class="c-label-middle"><?php _e( 'size', 'woocommerce' ) ?></span>         </div>         <div class="c-details-col c-details-col_2">           <span class="c-label-middle"><?php echo esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ); ?></span>         </div>     </div> <?php endif; ?> 

i can see need filter get_dimensions(); function not know how re-order array?

i see list_attributes(); deprecated on how - using new wc_display_product_attributes method if possible great.

first, since woocommerce 3 wc_product list_attributes() method deprecated , it's replaced wc_display_product_attributes( $product ).

to change product dimensions order, need first make own function:

function get_product_dimensions_custom(){     global $product;      return  wc_format_dimensions( array(         'length' => $product->get_length(),         'height' => $product->get_height(),         'width'  => $product->get_width(),     )); } 

code goes in function.php file of active child theme (or theme) or in plugin file.

then can use in template customization:

<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>     <div class="c-details-row">         <div class="c-details-col c-details-col_1">           <span class="c-label-middle"><?php _e( 'size', 'woocommerce' ) ?></span>         </div>         <div class="c-details-col c-details-col_2">           <span class="c-label-middle"><?php echo esc_html( get_product_dimensions_custom() ); ?></span>         </div>     </div> <?php endif; ?> 

to finish custom hooked function in woocommerce_single_product_summary be:

add_action( 'woocommerce_single_product_summary', 'wsa_show_product_dimensions', 25 ); function wsa_show_product_dimensions() {     global $product;      echo wc_display_product_attributes( $product );  } 

code goes in function.php file of active child theme (or theme) or in plugin file.

this code tested on woocommerce 3+ , works;


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -