• Resolved phelps1990

    (@phelps1990)


    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)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there! ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers! ??

    Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please feel free to start a new thread.

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.