Home Display calculated total volume in Woocommerce Order received totals
Reply: 0

Display calculated total volume in Woocommerce Order received totals

user5434
1#
user5434 Published in September 19, 2018, 11:03 am

I was kindly assisted with some code that helped to add the combined value of custom field attached to each product - in this case volume of whole order in m3.

I would like to display the m3 volume in the table below product list on the thankyou page - does anyone know the hook i should use. Below is the code that shows my total volume on the cart and checkout page.

 add_action( 'woocommerce_cart_totals_before_shipping', 
'display_cart_volume_total', 20 );
add_action( 'woocommerce_review_order_before_shipping', 
'display_cart_volume_total', 20 );
 function display_cart_volume_total() {
$total_volume = 0;

// Loop through cart items and calculate total volume
foreach( WC()->cart->get_cart() as $cart_item ){
    $product_volume = (float) get_post_meta( $cart_item['product_id'], 
'_item_volume', true );
    $total_volume  += $product_volume * $cart_item['quantity'];
}

if( $total_volume > 0 ){

    // The Output
    echo ' <tr class="cart-total-volume">
        <th>' . __( "Total Shipping Volume", "woocommerce" ) . '</th>
        <td data-title="total-volume">' . number_format($total_volume, 2) . 
 ' m3</td>
    </tr>';
  }
 }
share|improve this question

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306282 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO