global $woocommerce; $items = $woocommerce->cart->get_cart(); $data = $_REQUEST; $payment_first_name = $data['payment_first_name']; $payment_last_name = $data['payment_last_name']; $billing_adress_same = $data['billing_adress_same']; $billing_address = $data['billing_address']; $billing_city = $data['billing_city']; $billing_state = $data['billing_state']; $billing_post_code = $data['billing_post_code']; $payment_method = $data['payment_method']; $creadit_card_first_name = $data['creadit_card_first_name']; $creadit_card_last_name = $data['creadit_card_last_name']; $eway_payments_card_number = $data['eway_payments-card-number']; $eway_payments_card_expiry_year = $data['eway_payments-card-expiry-year']; $eway_payments_card_expiry_month = $data['eway_payments-card-expiry-month']; $eway_payments_card_cvc = $data['eway_payments-card-cvc']; $desktop_terms_condition = $data['desktop_terms_condition']; $shipping = array( 'first_name' =>$_SESSION['book_first_name'], 'last_name' =>$_SESSION['book_last_name'], 'company' =>'', 'email' =>$_SESSION['book_email'], 'phone' =>$_SESSION['book_mobile_number'], 'address_1' =>$_SESSION['book_address'], 'address_2' =>'', 'city' =>$_SESSION['book_city'], 'state' =>$_SESSION['book_state'], 'postcode' =>$_SESSION['book_post_code'], 'country' =>'AUS' ); if(isset($data['billing_adress_same']) && $data['billing_adress_same'] == 1){ $address = array( 'first_name' =>$data['payment_first_name'], 'last_name' =>$data['payment_last_name'], 'company' =>'', 'email' =>$_SESSION['book_email'], 'phone' =>$_SESSION['book_mobile_number'], 'address_1' =>$_SESSION['book_address'], 'address_2' =>'', 'city' =>$_SESSION['book_city'], 'state' =>$_SESSION['book_state'], 'postcode' =>$_SESSION['book_post_code'], 'country' =>'AUS' ); } else { $address = array( 'first_name' => $data['payment_first_name'], 'last_name' => $data['payment_last_name'], 'company' =>'', 'email' =>$_SESSION['book_email'], 'phone' =>$_SESSION['book_mobile_number'], 'address_1' =>$data['billing_address'], 'address_2' =>'', 'city' =>$data['billing_city'], 'state' =>$data['billing_state'], 'postcode' =>$data['billing_post_code'], 'country' =>'AUS' ); } if(!isset($_SESSION['current_order_seeion']) || $_SESSION['current_order_seeion'] == ""){ $order = wc_create_order(); if(!empty($items)){ foreach($items as $item => $values) { $order->add_product( get_product($values['product_id']),$values['quantity']); } } $order->set_address( $address, 'billing' ); $order->set_address( $shipping, 'shipping' ); $order->calculate_totals(); $order_id = $order->id; if($_SESSION['for_gift'] == "yes"){ add_post_meta($order_id,'gift_data',$varDataArr = array('for_gift' =>$_SESSION['for_gift'],'gift_first_name'=>$_SESSION['gift_first_name'],'gift_last_name'=>$_SESSION['gift_last_name'],'gift_mobile_number'=>$_SESSION['gift_mobile_number'],'gift_email'=>$_SESSION['gift_email'],'gift_address'=>$_SESSION['gift_address'],'gift_city'=>$_SESSION['gift_city'],'gift_state'=>$_SESSION['gift_state'],'gift_post_code'=>$_SESSION['gift_post_code'])); } update_post_meta( $order_id, 'book_start_month', sanitize_text_field( $_SESSION['book_start_session'] ) ); update_post_meta( $order_id, 'book_session_time', sanitize_text_field( $_SESSION['book_session'] ) ); } else { $order_id = $_SESSION['current_order_seeion']; } define( 'WOOCOMMERCE_CHECKOUT', true ); $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); if($payment_method == "paypal"){ $result = $available_gateways['paypal']->process_payment($order_id); if($result['result'] == 'failure'){ $_SESSION['current_order_seeion'] = $order_id; echo json_encode(array('result' => 'fail', 'message' => 'Please enter valid Creadit Card Information')); } else { echo json_encode(array('result' => 'success', 'redirect' => $result['redirect'])); } } else { $result = $available_gateways['eway_payments']->process_payment($order_id); if($result['result'] == 'failure'){ $_SESSION['current_order_seeion'] = $order_id; echo json_encode(array('result' => 'fail', 'message' => 'Please enter valid Creadit Card Information')); } else { echo json_encode(array('result' => 'success', 'redirect' => $result['redirect'])); } } die();