Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Last active September 20, 2018 13:10
Show Gist options
  • Save gschoppe/71a35ffbac494d0ac2ceba9ce5d715d4 to your computer and use it in GitHub Desktop.
Save gschoppe/71a35ffbac494d0ac2ceba9ce5d715d4 to your computer and use it in GitHub Desktop.
This function will return formatted HTML to display box dimensions and weights for multibox and non-multibox products
<?php
function get_multibox_dimension_output( $product_id = false ) {
$product = wc_get_product( $product_id );
if( !$product ) {
return;
}
$output = '';
$boxes = get_post_meta( $product->ID, '_wc-multibox-additional-boxes', true );
if( $boxes ) {
var $i = 1;
foreach( $boxes as $box ) {
$dimensions = wc_format_dimensions( $box );
$weight = wc_format_weight( $box['weight'] );
$output .= '<div class="product-meta"><span class="product-meta-label">Box ' . $i . 'Dimensions: </span>' . $dimensions . '</div>';
$output .= '<div class="product-meta"><span class="product-meta-label">Box ' . $i . 'Weight: </span>' . $weight . '</div>';
$i++;
}
} else {
$dimensions = wc_format_dimensions( $product->get_dimensions( false ) );
$weight = wc_format_weight( $product->get_weight() );
if ( $product->has_dimensions() ) {
$output .= '<div class="product-meta"><span class="product-meta-label">Dimensions: </span>' . $dimensions . '</div>';
$output .= '<div class="product-meta"><span class="product-meta-label">Weight: </span>' . $weight . '</div>';
}
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment