Store the volume of an order in the DB
-
Hi everyone, hope you are all fine.
I am not really sure of wat i am doing, but in a nutshell i want to calculate the volume of an order and sore it in the DB. I am working with the woocommerce Rest API and when i retrive the orgder i dont have the 3 measur of the item bought so i tought to do as i have already don with the total weight sored as a meta data in the db and then retreived trough the API.i ma doing like this but it breaks me the closing of the order. I receive the message Internal server Error. Can you help me to adjust it?
// Store volume in the database add_action('woocommerce_checkout_update_order_meta', 'woo_add_cart_volume'); function woo_add_cart_volume( $order_id ) { global $woocommerce; foreach( $order->get_items() as $item ){ $product_volume = (float) get_post_meta( $item->get_product_id(), '_item_volume', true ); $total_volume += $product_volume * $item->get_quantity(); } update_post_meta( $order_id, '_item_volume', $total_volume ); }
Thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Store the volume of an order in the DB’ is closed to new replies.