The woocommerce_checkout_process hook is very useful when you want to validate anything before the order is processed.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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 ); } |