WooCommerce Get Order Product Details Before Payment in Plugin

woocommerce_checkout_process

The woocommerce_checkout_process hook is very useful when you want to validate anything before the order is processed.

add_action('woocommerce_checkout_process', 'woocommerce_get_data', 10);
function woocommerce_get_data(){

    $cart = array();
    $items = WC()->cart->get_cart();
    foreach($items as $i=>$fetch){
        $item = $fetch['data']->post;

        $cart[]=array(
            'code'        => $fetch['product_id'], 
            'name'        => $item->post_title, 
            'description' => $item->post_content, 
            'quantity'    => $fetch['quantity'], 
            'amount'      => get_post_meta($fetch['product_id'], '_price', true)
        );
    }

    $user = wp_get_current_user();

    $data = array(
        'total' => WC()->cart->total,
        'cart'  => $cart,
        'user'  => array(
            'id' => $user->ID,
            'name' => join(' ',array_filter(array($user->user_firstname, $user->user_lastname))),
            'mail' => $user->user_email,
        )
    );

    $_SESSION['woo_data']=json_encode($data);

}