sarah miller
sarah miller

Reputation: 193

Display product dimension in WooCommerce product summary

In WooCommerce I would like to Display Product Dimensions from product metabox in summary of single product pages. Is it possible?

Any track is appreciated.


Edit - More detail:

I have an option in my theme setting like this:
Theme Setting Option


When I enable this option I have product page like this image:
Single Product Page
I'd like to disable this option from my theme setting and then use a snippet to show Dimensions only.

Upvotes: 1

Views: 2922

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254448

The following hooked function will display formatted product dimensions (only) under product short description in product single pages:

add_action( 'woocommerce_single_product_summary', 'display_product_formated_dimensions_table', 25 );
function display_product_formated_dimensions_table(){
    global $product;

    if ( $product->has_dimensions() ) {
        echo '<table class="shop_attributes"><tr>
            <th>' . __( 'Dimensions', 'woocommerce' ) . '</th>
            <td class="product_dimensions">' . esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ) . '</td>
        </tr></table>';
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

Upvotes: 2

Related Questions