if ($orderId) { if ($orderStatus == 'INITIALIZED') { /**update the db**/ $now = current_time('timestamp'); //$thisOrderTransactionId='COD'.$now.$orderId.''; $thisOrderPostVars = apply_filters('wppizza_filter_sanitize_post_vars', $params); /**add wpml language code so we can send emails in the right language**/ if (defined('ICL_LANGUAGE_CODE')) { $thisOrderPostVars['wppizza_wpml_lang'] = ICL_LANGUAGE_CODE; } $gatewayUsed = strtoupper($thisOrderPostVars['wppizza-gateway']); $thisOrderPostVars = esc_sql(serialize($thisOrderPostVars)); $thisOrderTransactionId = $gatewayUsed . $now . $orderId . ''; $wpdb->query("UPDATE " . $wpdb->prefix . $this->pluginOrderTable . " SET\n\t\t\ttransaction_id='" . $thisOrderTransactionId . "',\n\t\t\tinitiator='" . $gatewayUsed . "',\n\t\t\tcustomer_ini='" . $thisOrderPostVars . "'\n\t\t\tWHERE id='" . $orderId . "' "); /**send the email***/ $mailResults = $sendEmail->wppizza_order_send_email($orderId); //orig /**update again to see if mail was sent successfully**/ $updateDb = true; } else { $mailResults['error'] = __('This order has already been processed', $this->pluginLocale); } } /***update order******/ if (isset($updateDb)) { if ($mailResults['status']) { $mailSent = 'Y'; $mailError = ''; $paymentStatus = 'COMPLETED'; $transactionDetails = __('SUCCESS', $this->pluginLocale); } else {
function wppizza_gateway_complete_order($orderId, $blogid = false, $logging = false, $sendAdminErrors = false) { global $wpdb; $orderId = (int) $orderId; /**select the right blog table */ if ($blogid && is_int($blogid) && $blogid > 1) { $wpdb->prefix = $wpdb->base_prefix . $blogid . '_'; } /**********new send order email class**************/ $sendEmail = new WPPIZZA_SEND_ORDER_EMAILS(); /************************************************************ * * [send the emails returns array * ['status']->true/false * ['error']->''/msg * ['mailer']->mail function name * ************************************************************/ $mailResults = $sendEmail->wppizza_order_send_email($orderId, $blogid); /******************************************************************** * * [depending on $mailResults['status'], * will insert order into db and output "thankyou" * or justs displays error] * ********************************************************************/ /*update db*/ $dbupd['customer_details'] = '' . $sendEmail->customerDetails . ''; $dbupd['order_details'] = '' . $sendEmail->orderDetails . ''; $dbupd['payment_status'] = 'COMPLETED'; //$dbupd['transaction_details'] = esc_sql(serialize($gatewayReply)); $dbupd['transaction_errors'] = ''; $dbupd['mail_sent'] = !empty($mailResults['status']) ? 'Y' : 'N'; $dbupd['mail_error'] = !empty($mailResults['error']) ? esc_sql(maybe_serialize($mailResults['error'])) : ''; $fields = ''; $i = 0; foreach ($dbupd as $k => $v) { if ($i > 0) { $fields .= ", "; } $fields .= "" . $k . "='" . $v . "'"; $i++; } $sql = "UPDATE " . $wpdb->prefix . $this->pluginOrderTable . " SET " . $fields . " WHERE id='" . $orderId . "' "; $wpdb->query($sql); /**do additional stuff when order has been executed*/ do_action('wppizza_on_order_executed', $orderId, $this->pluginOrderTable); if (!$mailResults['status'] && $sendAdminErrors) { $this->wppizza_gateway_send_errors_to_admin(true, $blogid, $orderId, false, $mailResults); } /**logging**/ if (!$mailResults['status']) { $this->wppizza_gateway_logging($logging, $blogid, $orderId, $mailResults, 'mail-error'); } else { $this->wppizza_gateway_logging($logging, $blogid, $orderId, 'Order ID:' . $orderId . PHP_EOL . 'Customer Details:' . PHP_EOL . print_r($sendEmail->customerDetails, true) . PHP_EOL . 'Order Details:' . PHP_EOL . print_r($sendEmail->orderDetails, true) . PHP_EOL . PHP_EOL, 'success'); } }