public static function get_test_customer($country = 'US', $state = 'CO', $zip = '80111', $city = 'Greenwood Village') { global $woocommerce; $customer = new WC_Customer(); $customer->set_shipping_location($country, $state, $zip, $city); return $customer; }
/** * Get a hash of the customer location. * @return string */ public static function geolocation_ajax_get_location_hash() { $customer = new WC_Customer(0, true); $location = array(); $location['country'] = $customer->get_billing_country(); $location['state'] = $customer->get_billing_state(); $location['postcode'] = $customer->get_billing_postcode(); $location['city'] = $customer->get_billing_city(); return substr(md5(implode('', $location)), 0, 12); }
/** * Edit a customer * * @since 2.2 * @param int $id the customer ID * @param array $data * @return array */ public function edit_customer($id, $data) { try { if (!isset($data['customer'])) { throw new WC_API_Exception('woocommerce_api_missing_customer_data', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'customer'), 400); } $data = $data['customer']; // Validate the customer ID. $id = $this->validate_request($id, 'customer', 'edit'); // Return the validate error. if (is_wp_error($id)) { throw new WC_API_Exception($id->get_error_code(), $id->get_error_message(), 400); } $data = apply_filters('woocommerce_api_edit_customer_data', $data, $this); $customer = new WC_Customer($id); // Customer email. if (isset($data['email'])) { $customer->set_email($data['email']); } // Customer password. if (isset($data['password'])) { $customer->set_password($data['password']); } // Update customer data. $this->update_customer_data($customer->get_id(), $data, $customer); $customer->save(); do_action('woocommerce_api_edit_customer', $customer->get_id(), $data); return $this->get_customer($customer->get_id()); } catch (Exception $e) { return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); } }
/** * Test setting meta. * @since 2.7.0 */ public function test_set_meta() { $customer = WC_Helper_Customer::create_customer(); $customer_id = $customer->get_id(); $meta_value = time() . '-custom-value'; $customer->add_meta_data('my-field', $meta_value, true); $customer->save(); $customer = new WC_Customer($customer_id); $this->assertEquals($meta_value, $customer->get_meta('my-field')); }
/** * Update customer meta fields. * * @param WC_Customer $customer * @param WP_REST_Request $request */ protected function update_customer_meta_fields($customer, $request) { $schema = $this->get_item_schema(); // Meta data if (isset($request['meta_data'])) { if (is_array($request['meta_data'])) { foreach ($request['meta_data'] as $meta) { $coupon->update_meta_data($meta['key'], $meta['value'], $meta['id']); } } } // Customer first name. if (isset($request['first_name'])) { $customer->set_first_name(wc_clean($request['first_name'])); } // Customer last name. if (isset($request['last_name'])) { $customer->set_last_name(wc_clean($request['last_name'])); } // Customer billing address. if (isset($request['billing'])) { foreach (array_keys($schema['properties']['billing']['properties']) as $field) { if (isset($request['billing'][$field]) && is_callable(array($customer, "set_billing_{$field}"))) { $customer->{"set_billing_{$field}"}($request['billing'][$field]); } } } // Customer shipping address. if (isset($request['shipping'])) { foreach (array_keys($schema['properties']['shipping']['properties']) as $field) { if (isset($request['shipping'][$field]) && is_callable(array($customer, "set_shipping_{$field}"))) { $customer->{"set_shipping_{$field}"}($request['shipping'][$field]); } } } }
$zip = 'Zip'; break; default: $state = ''; $zip = ''; break; } if (isset($_COOKIE['builder_user'])) { $customer = unserialize(str_replace('\\"', '"', $_COOKIE['builder_user'])); foreach ($customer as $field => $value) { if ($field == 'billing_state') { $state = $value; } } } elseif (is_user_logged_in()) { $customer_data = new WC_Customer(); global $current_user; get_currentuserinfo(); $customer = array('billing_first_name' => $current_user->user_firstname, 'billing_last_name' => $current_user->user_lastname, 'billing_email' => $current_user->user_email, 'billing_phone' => '', 'billing_address_1' => $customer_data->get_address(), 'billing_address_2' => $customer_data->get_address_2(), 'billing_city' => $customer_data->get_city(), 'billing_postcode' => $customer_data->get_postcode(), 'billing_state' => $customer_data->get_state()); } ?> <style type="text/css" media="screen"> #contact_form { padding-bottom:20px; } #contact_form .field_block { float:left; width:45%; margin-right:5%; padding-bottom:10px; } #contact_form .field_block label { display:block; font-weight:bold; } #contact_form .field_block input, #contact_form .field_block select { width:100%; } </style> <div id="contact_form"> <div class="field_block">
/** * Generate form * @param $order_id * @return string */ function generate_pagantis_eom_form($order_id) { //Logs $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde'); $order = new WC_Order($order_id); //Total Amount $transaction_amount = number_format((double) $order->get_total(), 2, '.', ''); $transaction_amount = str_replace('.', '', $transaction_amount); $transaction_amount = floatval($transaction_amount); // Product Description $products = WC()->cart->cart_contents; $i = 1; $products_form = ""; $description = ""; foreach ($products as $product) { $products_form .= "\r\n <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n <input name='items[" . $i . "][amount]' type='hidden' value='" . $product['data']->price * $product['quantity'] . "'>\r\n "; $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')'; $i++; } $shipping = $order->get_items('shipping'); foreach ($shipping as $shipping_method) { if ($shipping_method['cost'] > 0) { $products_form .= "\r\n <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n "; $description[] = 'Gastos de envio'; $i++; } } $this->ok_url = $this->get_return_url($order); $this->ko_url = htmlspecialchars_decode($order->get_cancel_order_url()); $account_id = ""; $dataToEncode = ""; //Test Environment Selected if ($this->environment == self::TEST_ENVIRONMENT) { $this->key = $this->test_key; $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url; $account_id = $this->test_account; } else { $this->key = $this->real_key; $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url; $account_id = $this->real_account; } $signature = sha1($dataToEncode); $form_url = $this->paga_mastarde_url; $adressInfo = explode("/", $order->billing_city); $customer = new WC_Customer(); $countries = new WC_Countries(); $address = $customer->get_address() . " " . $customer->get_address_2(); $city = $customer->get_city(); $postcode = $customer->get_postcode(); $states = $countries->get_states(); $state = $states[$order->shipping_country][$customer->get_state()]; //todo can include shipping information //Create Form $buyer_name = $order->billing_first_name . " " . $order->billing_last_name; $pagantis_form_fields = "\r\n <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n\r\n <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n " . $products_form . "\r\n\r\n <!-- firma de la operación -->\r\n <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n <!-- discount -->\r\n <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n <!-- callback url -->\r\n <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n <!-- address -->\r\n <input name='address[street]' type='hidden' value='" . $address . "'>\r\n <input name='address[city]' type='hidden' value='" . $city . "'>\r\n <input name='address[province]' type='hidden' value='" . $state . "'>\r\n <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n <!-- eom -->\r\n <input name='end_of_month' type='hidden' value='true'>\r\n <!-- phone -->\r\n\r\n <input name='phone' type='hidden' value='" . $order->billing_phone . "'>\r\n "; $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form"> ' . $pagantis_form_fields . ' <a class="button cancel floatLeft" href="' . $order->get_cancel_order_url() . '">' . __('Cancelar Pedido', 'pagantis') . '</a> <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" /> </form>'; if ($this->iframe == 'true') { $return_form .= "<script type='text/javascript'>\r\n\r\n jQuery(document).ready(function() {\r\n if (jQuery.isFunction(jQuery.fancybox) ){\r\n jQuery('#submit_vme_payment_form').on('click', function (e) {\r\n e.preventDefault(); // avoids calling success.php from the link\r\n //post data to get form url.\r\n jQuery.ajax({\r\n type: 'POST',\r\n url: '" . get_site_url() . "/wp-content/plugins/pagamastarde-payment-gateway-for-woocommerce/getPmtUrl.php',\r\n data: jQuery('#pagantis_payment_form').serialize(),\r\n success: function(data, textStatus, jqXHR)\r\n {\r\n jQuery.fancybox({\r\n // fancybox API options\r\n type: 'iframe',\r\n fitToView: false,\r\n openEffect: 'none',\r\n closeEffect: 'none',\r\n 'width' : 920,\r\n 'minHeight' : 230,\r\n 'href': data\r\n }); // fancybox\r\n }\r\n });\r\n }); // on\r\n }\r\n }); //ready\r\n\r\n </script>"; } return $return_form; }
/** * Get total orders by customer. * @param int $user_id * @return int */ function wc_get_customer_order_count($user_id) { $customer = new WC_Customer($user_id); return $customer->get_order_count(); }
/** * Generate form * @param $order_id * @return string */ function generate_pagantis_form($order_id) { //Logs $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde'); $order = new WC_Order($order_id); //Total Amount $transaction_amount = number_format((double) $order->get_total(), 2, '.', ''); $transaction_amount = str_replace('.', '', $transaction_amount); $transaction_amount = floatval($transaction_amount); // Product Description $products = WC()->cart->cart_contents; $i = 1; $products_form = ""; $description = ""; foreach ($products as $product) { $products_form .= "\r\n <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n <input name='items[" . $i . "][amount]' type='hidden' value='" . round(($product['data']->price + $product['line_tax']) * $product['quantity'], 2) . "'>\r\n "; $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')'; $i++; } $shipping = $order->get_items('shipping'); foreach ($shipping as $shipping_method) { if ($shipping_method['cost'] > 0) { $products_form .= "\r\n <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n "; $description[] = 'Gastos de envio'; $i++; } } $account_id = ""; $dataToEncode = ""; $this->ok_url = $this->get_return_url($order); $this->ko_url = htmlspecialchars_decode(WC_Cart::get_checkout_url()); $this->cancelled_url = htmlspecialchars_decode(WC_Cart::get_checkout_url()); //Test Environment Selected if ($this->environment == self::TEST_ENVIRONMENT) { $this->key = $this->test_key; $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url; $account_id = $this->test_account; } else { $this->key = $this->real_key; $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url; $account_id = $this->real_account; } $signature = hash('sha512', $dataToEncode); $form_url = $this->paga_mastarde_url; $adressInfo = explode("/", $order->billing_city); $customer = new WC_Customer(); $countries = new WC_Countries(); $address = $customer->get_address() . " " . $customer->get_address_2(); $city = $customer->get_city(); $postcode = $customer->get_postcode(); $states = $countries->get_states(); $state = $states[$order->shipping_country][$customer->get_state()]; $saddress = $customer->shipping_address_1 . " " . $customer->shipping_address_2; $scity = $customer->shipping_city; $spostcode = $customer->shipping_postcode; $sstate = $states[$order->shipping_country][$customer->shipping_state]; //Create Form $buyer_name = $order->billing_first_name . " " . $order->billing_last_name; $pagantis_form_fields = "\r\n <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n <input name='cancelled_url' type='hidden' value='" . $this->cancelled_url . "' />\r\n\r\n <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n " . $products_form . "\r\n\r\n <!-- firma de la operación -->\r\n <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n <!-- discount -->\r\n <input name='discount[full]' type='hidden' value='" . $this->discount . "' />\r\n <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n <!-- callback url -->\r\n <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n <!-- address -->\r\n <input name='address[street]' type='hidden' value='" . $address . "'>\r\n <input name='address[city]' type='hidden' value='" . $city . "'>\r\n <input name='address[province]' type='hidden' value='" . $state . "'>\r\n <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n <input name='shipping[street]' type='hidden' value='" . $saddress . "'>\r\n <input name='shipping[city]' type='hidden' value='" . $scity . "'>\r\n <input name='shipping[province]' type='hidden' value='" . $sstate . "'>\r\n <input name='shipping[zipcode]' type='hidden' value='" . $spostcode . "'>\r\n\r\n <!-- phone -->\r\n\r\n <input name='mobile_phone' type='hidden' value='" . $order->billing_phone . "'>\r\n "; $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form"> ' . $pagantis_form_fields . ' <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" /> </form>'; if ($this->iframe == 'true') { wp_enqueue_style('style', esc_url(plugins_url('pages/assets/css/iframe.css', __FILE__))); $return_form .= '<div id="myModal" class="paylater_modal"> <!-- Modal content --> <div class="paylater_modal-content"> <span id="paylater_close">x</span> <iframe id="iframe-pagantis" name="iframe-pagantis" style="width:100%;height:600px;display:block"></iframe> </div> </div>'; $return_form .= '<script type="text/javascript"> el = document.getElementById("submit_vme_payment_form"); el.addEventListener("click", function (e){ e.preventDefault(); document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis"); document.getElementById("pagantis_payment_form").submit(); document.getElementById("iframe-pagantis").style.display = "block"; document.getElementById("myModal").style.display = "block"; }); var closeModal = function closeModal(evt) { evt.preventDefault(); document.getElementById("myModal").style.display = "none"; }; var elements = document.querySelectorAll("#paylater_close, #myModal"); Array.prototype.forEach.call(elements, function(el){ el.addEventListener("click", closeModal); }); document.addEventListener("DOMContentLoaded", function(event) { document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis"); document.getElementById("pagantis_payment_form").submit(); document.getElementById("iframe-pagantis").style.display = "block"; document.getElementById("myModal").style.display = "block"; }); </script>'; } else { $return_form .= "<script type='text/javascript'>\r\n jQuery(document).ready(function() {\r\n jQuery('#submit_vme_payment_form').click();\r\n });\r\n </script>"; } return $return_form; }
/** * Get the customer for the given ID * * @since 2.1 * @param int $id the customer ID * @param string $fields * @return array */ public function get_customer($id, $fields = null) { global $wpdb; $id = $this->validate_request($id, 'customer', 'read'); if (is_wp_error($id)) { return $id; } $customer = new WC_Customer($id); $last_order = $customer->get_last_order(); $customer_data = array('id' => $customer->get_id(), 'created_at' => $this->server->format_datetime($customer->get_date_created(), false, true), 'email' => $customer->get_email(), 'first_name' => $customer->get_first_name(), 'last_name' => $customer->get_last_name(), 'username' => $customer->get_username(), 'last_order_id' => is_object($last_order) ? $last_order->get_id() : null, 'last_order_date' => is_object($last_order) ? $this->server->format_datetime($last_order->get_date_created(), false, true) : null, 'orders_count' => $customer->get_order_count(), 'total_spent' => wc_format_decimal($customer->get_total_spent(), 2), 'avatar_url' => $customer->get_avatar_url(), 'billing_address' => array('first_name' => $customer->get_billing_first_name(), 'last_name' => $customer->get_billing_last_name(), 'company' => $customer->get_billing_company(), 'address_1' => $customer->get_billing_address_1(), 'address_2' => $customer->get_billing_address_2(), 'city' => $customer->get_billing_city(), 'state' => $customer->get_billing_state(), 'postcode' => $customer->get_billing_postcode(), 'country' => $customer->get_billing_country(), 'email' => $customer->get_billing_email(), 'phone' => $customer->get_billing_phone()), 'shipping_address' => array('first_name' => $customer->get_shipping_first_name(), 'last_name' => $customer->get_shipping_last_name(), 'company' => $customer->get_shipping_company(), 'address_1' => $customer->get_shipping_address_1(), 'address_2' => $customer->get_shipping_address_2(), 'city' => $customer->get_shipping_city(), 'state' => $customer->get_shipping_state(), 'postcode' => $customer->get_shipping_postcode(), 'country' => $customer->get_shipping_country())); return array('customer' => apply_filters('woocommerce_api_customer_response', $customer_data, $customer, $fields, $this->server)); }
/** * Test WC_Customer's session handling code. * @since 2.7.0 */ public function test_customer_sessions() { $customer = WC_Helper_Customer::create_customer(); $session = WC_Helper_Customer::create_mock_customer(); // set into session.... $this->assertEquals('19123', $session->get_billing_postcode()); $this->assertEquals('123 South Street', $session->get_billing_address()); $this->assertEquals('Philadelphia', $session->get_billing_city()); $session->set_billing_address('124 South Street'); $session->save_to_session(); $session = new WC_Customer(0, true); $session->load_session(); $this->assertEquals('124 South Street', $session->get_billing_address()); $session = new WC_Customer(0, true); $session->load_session(); $session->set_billing_postcode('32191'); $session->save(); // should still be session ID, not a created row, since we are working with guests/sessions $this->assertFalse($session->get_id() > 0); $this->assertEquals('32191', $session->get_billing_postcode()); }
/** * Search for customers and return json. */ public static function json_search_customers() { ob_start(); check_ajax_referer('search-customers', 'security'); if (!current_user_can('edit_shop_orders')) { die(-1); } $term = wc_clean(stripslashes($_GET['term'])); $exclude = array(); if (empty($term)) { die; } $data_store = WC_Data_Store::load('customer'); $ids = $data_store->search_customers($term); $found_customers = array(); if (!empty($_GET['exclude'])) { $ids = array_diff($ids, (array) $_GET['exclude']); } foreach ($ids as $id) { $customer = new WC_Customer($id); /* translators: 1: user display name 2: user ID 3: user email */ $found_customers[$id] = sprintf(esc_html__('%1$s (#%2$s – %3$s)', 'woocommerce'), $customer->get_first_name() . ' ' . $customer->get_last_name(), $customer->get_id(), $customer->get_email()); } wp_send_json(apply_filters('woocommerce_json_search_found_customers', $found_customers)); }
function send_to_printer2($order_id, $PID = -1, $reqfrom = "woocommerce") { global $wpdb; $order = wc_get_order($order_id); if ($PID == -1 && $reqfrom == "woocommerce") { $PID = $_SESSION['sentimentPID']; } // Update Order So that it is stored in the flatterbox $currentOrders = get_field('order_count', $PID); if (strlen($currentOrders) > 0) { $currentOrders .= ','; } $currentOrders .= $order_id; __update_post_meta($PID, 'order_count', $value = $currentOrders); $orderAddOns = wc_checkout_add_ons()->get_order_add_ons($order_id); $gift = 'No'; $extracards = 0; if ($orderAddOns[2]['value'] == 1) { $gift = 'Yes'; } if ($orderAddOns[3]['value'] == 1) { $extracards = 10; } // Not needed I dont think //print_r($orderAddOns); $order_count = 1; //print_r($order); //print_r($_SESSION); do_action('woocommerce_order_details_after_customer_details', $order); $_customer = new WC_Customer($order_id); $shipping_address = $order->get_formatted_shipping_address(); $name = explode('<br/>', $shipping_address); $name = $name[0]; // echo $shipping_address; // print_r($_customer); $blankcolor = ''; $shipping_method = $order->get_shipping_method(); switch (strtoupper($shipping_method)) { case 'FEDEX EXPRESS SAVER': $shipping_method = 'FDEX_EXPRESSSAVER'; break; case 'FEDEX 2DAY': $shipping_method = 'FDEX_FEDEX2DAY'; break; case 'FEDEX PRIORITY OVERNIGHT': $shipping_method = 'FDEX_PRIORITYOVERNIGHT'; break; default: $shipping_method = 'FDXG_FEDEXGROUND'; break; } $xmlstring = '<?xml version="1.0" encoding="UTF-8"?>'; // Open Order $xmlstring .= ' <order xmlns="http://fbns/">'; if (count($order->get_items()) > 0) { foreach ($order->get_items() as $item) { // Reset Additional Count if ($orderAddOns[3]['value'] == 1) { $extracards = 10; } else { $extracards = 0; } // Add element $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item); $qty = intval($item["pa_cardquantity"]) + $extracards; //print_r($_product); //print_r($item); //$_item = $order->get_item_meta(784); // 781 784 /* echo '------------'; echo $_item; print_r($_item); echo '------------'; */ // Start Box $xmlstring .= ' <subOrder> <orderId>' . $order_id . '-' . str_pad($order_count, 3, '0', STR_PAD_LEFT) . '</orderId> <orderDate><![CDATA[' . date('n/j/y', strtotime($order->order_date)) . ']]></orderDate> <shipTo><![CDATA[' . $name . ']]></shipTo> <shipAdd1><![CDATA[' . $_customer->get_shipping_address() . ']]></shipAdd1> <shipAdd2><![CDATA[' . $_customer->get_shipping_address_2() . ']]></shipAdd2> <shipCity><![CDATA[' . $_customer->get_shipping_city() . ']]></shipCity> <shipState><![CDATA[' . $_customer->get_shipping_state() . ']]></shipState> <shipZip><![CDATA[' . $_customer->get_shipping_postcode() . ']]></shipZip> <giftWrapped><![CDATA[' . $gift . ']]></giftWrapped>'; /* <specialInstructions><![CDATA['.htmlspecialchars_decode(stripslashes(get_field('special_instructions_to_flatterers', $PID))).']]></specialInstructions> */ $xmlstring .= ' <shipVia><![CDATA[' . $shipping_method . ']]></shipVia> <box> <shipQty>' . $item["qty"] . '</shipQty> <sku><![CDATA[' . $_product->get_sku() . '_' . $qty . ']]></sku> <font><![CDATA[Unknown]]></font> <substrate><![CDATA[Unknown]]></substrate> <boxType><![CDATA[' . $item["pa_boxtype"]; if (strlen($item["pa_boxcolor"]) > 0) { $xmlstring .= '-' . $item["pa_boxcolor"]; } $xmlstring .= ']]></boxType> <cardcolor><![CDATA[' . xmlPrepare($item["pa_cardcolor"]) . ']]></cardcolor>'; $blankcolor = xmlPrepare($item["pa_cardcolor"]); if (get_field('title_card_headline', $PID)) { $xmlstring .= ' <titlecard> <heading><![CDATA[' . xmlPrepare(get_field('title_card_headline', $PID)) . ']]></heading> <to><![CDATA[' . xmlPrepare(get_field('who_is_this_for', $PID)) . ']]></to> <from><![CDATA[' . xmlPrepare(get_field('title_card_name', $PID)) . ']]></from> </titlecard>'; } else { // For the blank parts $xmlstring .= ' <titlecard> <heading><![CDATA[]]></heading> <to><![CDATA[]]></to> <from><![CDATA[]]></from> </titlecard>'; } $sentiment_results = $wpdb->get_results("SELECT * FROM sentiments WHERE approved = 1 AND PID = " . $PID, ARRAY_A); $sentiment_count = $wpdb->num_rows; // Start Cards if ($sentiment_results) { foreach ($sentiment_results as $row) { $xmlstring .= ' <card> <note><![CDATA[' . xmlPrepare(preg_replace('/\\r/', '/R', preg_replace('/\\n(\\s*\\n)+/', '/R', preg_replace('/\\r\\n/', '/R', $row["sentiment_text"])))) . ']]></note> <author><![CDATA[' . xmlPrepare($row["sentiment_name"]) . ']]></author> <image><![CDATA[' . xmlPrepare($item["pa_cardcolor"]) . ']]></image> </card>'; } } // End Card $order_count++; // Increase Count // Extra Cards $addCards = intval($item["pa_cardquantity"]) - $sentiment_count; if ($addCards > 0) { $extracards = $extracards + $addCards; } for ($i = 0; $i < $extracards; $i++) { $xmlstring .= ' <card> <note><![CDATA[]]></note> <author><![CDATA[]]></author> <image><![CDATA[' . $blankcolor . ']]></image> </card>'; } // End Extra Cards $xmlstring .= ' </box> </subOrder>'; } // Close Box } // Close Order $xmlstring .= ' </order>'; // GET DATE $thedate = date("Ymd_Hi"); // Save File $file = $order_id . '_' . $thedate . '.xml'; //$myfile = fopen('orderlist/'.$file, "w"); //echo '<script>window.alert("HELLO -- '.$order_id.' -- '.getcwd().'");</script>'; if ($reqfrom == 'ajaxfunction') { file_put_contents('../../../orderlist/' . $file, $xmlstring); // Staging requires the ../ to be removed } else { file_put_contents('../orderlist/' . $file, $xmlstring); // Staging requires the ../ to be removed } if (false) { // removed as they are presently pulling $response = sftp_printer($file); } //echo '<script>window.alert("HELLO -- '.$order_id.' -- '.$response.'");</script>'; }
public function __construct() { _deprecated_function('woocommerce_customer', '1.4', 'WC_Customer()'); parent::__construct(); }
/** * Create a new customer account if needed. * @param array $data * @throws Exception */ protected function process_customer($data) { $customer_id = get_current_user_id(); if (!is_user_logged_in() && ($this->is_registration_required() || !empty($data['createaccount']))) { $username = !empty($data['account_username']) ? $data['account_username'] : ''; $password = !empty($data['account_password']) ? $data['account_password'] : ''; $customer_id = wc_create_new_customer($data['billing_email'], $username, $password); if (is_wp_error($customer_id)) { throw new Exception($customer_id->get_error_message()); } wp_set_current_user($customer_id); wc_set_customer_auth_cookie($customer_id); // As we are now logged in, checkout will need to refresh to show logged in data WC()->session->set('reload_checkout', true); // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering WC()->cart->calculate_totals(); } // Add customer info from other fields. if ($customer_id && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) { $customer = new WC_Customer($customer_id); $customer->set_first_name($data['billing_first_name']); $customer->set_last_name($data['billing_last_name']); foreach ($data as $key => $value) { if (is_callable(array($customer, "set_{$key}"))) { $customer->{"set_{$key}"}($value); } } $customer->save(); } do_action('woocommerce_checkout_update_user_meta', $customer_id, $data); }
function handlePaymentCompleted($order_id) { echo "-- handlePaymentCompleted"; $order = new WC_Order($order_id); $customer = new WC_Customer($order_id); $addresses = $order->get_address("shipping"); /* $To = get_option('admin_email').",dev_support@soixanteseize.com"; $Objet = $email_heading = "Vérifiez la commande ".$order_id; $message = $response[1]; ob_start(); include(COURIIERPATH.'views/mails/woo-couriier-order-ready.php'); $Body = ob_get_clean(); trace($Body); //sendCC($To, $Objet, $Body); return; */ $adresse = $addresses["address_1"] . ", "; if ($addresses["address_2"] != "") { $adresse .= $addresses["address_2"] . ", "; } $adresse .= $addresses["city"] . " "; $adresse .= $addresses["postcode"] . " "; //$postcode = $addresses["postcode"]; //trace($order); //trace($customer); //trace($order->get_address("shipping") ); //trace($adresse); $chosen_methods = $order->get_shipping_methods(); if (count($chosen_methods) > 0) { //$la_methode = object(); foreach ($chosen_methods as $c_method) { // trace($method); $chosen_method = $c_method['item_meta']['method_id'][0]; } //trace($chosen_method); $available_methods = WC()->session->get('shipping_methods_' . $addresses["postcode"]); //trace($available_methods); $offerIdTarifs = ''; foreach ($available_methods as $method) { //trace($method->speed); switch ($method->speed) { case 2: if ($chosen_method == 'couriier_classic_shipping_method') { $offerIdTarifs = $method->ref; } break; case 1: if ($chosen_method == 'couriier_rapide_shipping_method') { $offerIdTarifs = $method->ref; } break; case 0: if ($chosen_method == 'couriier_flash_shipping_method') { $offerIdTarifs = $method->ref; } break; } } //return; $adresse = $customer->get_address() . " " . $customer->get_postcode() . ", " . $customer->get_city(); $recipientLatLng = geoloc($adresse); //trace($customer); //trace($recipientLatLng); //trace($offerIdTarifs); //return; $body = array(array('offerIdTarifs' => $offerIdTarifs, 'pickupName' => get_bloginfo("name"), 'pickupLatitude' => PICKUPLAT, 'pickupLongitude' => PICKUPLNG, 'pickupAddress' => PICKUPADRESSE, 'pickupAddress2' => "test", 'pickupTel' => PICKUPTEL, 'pickupZip' => PICKUPZIP, 'pickupCity' => PICKUPCITY, 'recipientName' => $order->get_formatted_shipping_full_name(), 'recipientLatitude' => $recipientLatLng["lat"], 'recipientLongitude' => $recipientLatLng["lng"], 'recipientAddress' => $addresses["address_1"], 'recipientAddress2' => $addresses["address_2"], 'recipientTel' => $order->billing_phone, 'recipientZip' => $addresses["postcode"], 'recipientCity' => $addresses["city"], 'timeManagement' => "2015-04-24 00:00:00", 'deliveryType' => "En main propre")); //trace($body); //return; $body = json_encode($body); $url = COURIIER_WS . '/orders'; //trace($url); $response = api_call_post($url, $body); //trace($response); $response = json_decode($response['body']); //trace($response); $couriier_order_id = $response[0]->id; //trace($order_id); //return; if ($couriier_order_id) { /** url_order_follow **/ $url_order_follow = $response[0]->following_url; //trace($url_order_follow); if ($url_order_follow) { $To = $order->billing_email; $Objet = $email_heading = "Votre lien pour suivre la livraison Couriier"; ob_start(); include COURIIERPATH . 'views/mails/woo-couriier-order-follow.php'; $Body = ob_get_clean(); sendCC($To, $Objet, $Body); } /** url_order_ready **/ $url_rest_order_ready = get_bloginfo("url") . '/wc-api/couriier-order-ready?order_id=' . $order_id . '&couriier_order_id=' . $couriier_order_id; //$url_order_ready = COURIIER_WS.'/order/'.$couriier_order_id.'/ready'; //trace($url_rest_order_ready); //return; $To = get_option('admin_email') . ",dev_support@soixanteseize.com"; $Objet = $email_heading = "Votre lien pour lancer la livraison Couriier"; ob_start(); include COURIIERPATH . 'views/mails/woo-couriier-order-ready.php'; $Body = ob_get_clean(); //trace($Body); sendCC($To, $Objet, $Body); //return; } } else { $To = get_option('admin_email') . ",dev_support@soixanteseize.com"; $Objet = $email_heading = "U+026A0 Vérifiez la commande " . $order_id; $message = $response[1]; ob_start(); include COURIIERPATH . 'views/mails/woo-couriier-blank.php'; $Body = ob_get_clean(); //trace($Body); sendCC($To, $Objet, $Body); } //sendCC($To, $Objet, $Body); }
/** * Store customer data to meta. * @since 2.7.0 */ protected function update_customer_data() { if ($this->customer_id) { if (apply_filters('woocommerce_checkout_update_customer_data', true, $this)) { $customer = new WC_Customer($this->customer_id); if ($keys = array_keys($this->checkout_fields['billing'])) { foreach ($keys as $key) { if (is_callable(array($customer, "set_{$key}"))) { $customer->{"set_{$key}"}($this->get_posted_address_data(str_replace(array('billing_', 'shipping_'), '', $key))); } } } if (WC()->cart->needs_shipping() && ($keys = array_keys($this->checkout_fields['shipping']))) { foreach ($keys as $key) { if (is_callable(array($customer, "set_{$key}"))) { $customer->{"set_{$key}"}($this->get_posted_address_data(str_replace(array('billing_', 'shipping_'), '', $key), 'shipping')); } } } $customer->save(); } do_action('woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted); } }
function send_to_printer2($order_id) { global $wpdb; $order = wc_get_order($order_id); $orderAddOns = wc_checkout_add_ons()->get_order_add_ons($order_id); $gift = 'No'; $extracards = 0; if ($orderAddOns[2]['value'] == 1) { $gift = 'Yes'; } if ($orderAddOns[3]['value'] == 1) { $extracards = 10; } //print_r($orderAddOns); $order_count = 1; //print_r($order); //print_r($_SESSION); $PID = $_SESSION['sentimentPID']; do_action('woocommerce_order_details_after_customer_details', $order); $_customer = new WC_Customer($order_id); $shipping_address = $order->get_formatted_shipping_address(); $name = explode('<br/>', $shipping_address); $name = $name[0]; // echo $shipping_address; // print_r($_customer); $blankcolor = ''; $xmlstring = '<?xml version="1.0" encoding="UTF-8"?>'; // Open Order $xmlstring .= ' <order>'; if (count($order->get_items()) > 0) { foreach ($order->get_items() as $item) { // Add element $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item); //print_r($_product); //print_r($item); //$_item = $order->get_item_meta(784); // 781 784 /* echo '------------'; echo $_item; print_r($_item); echo '------------'; */ // Start Box $xmlstring .= ' <orderId>' . $order_id . '-' . str_pad($order_count, 3, '0', STR_PAD_LEFT) . '</orderId> <orderDate><![CDATA[' . date('n/j/y', strtotime($order->order_date)) . ']]></orderDate> <shipTo><![CDATA[' . $name . ']]></shipTo> <shipAdd1><![CDATA[' . $_customer->get_shipping_address() . ']]></shipAdd1> <shipAdd2><![CDATA[' . $_customer->get_shipping_address_2() . ']]></shipAdd2> <shipCity><![CDATA[' . $_customer->get_shipping_city() . ']]></shipCity> <shipState><![CDATA[' . $_customer->get_shipping_state() . ']]></shipState> <shipZip><![CDATA[' . $_customer->get_shipping_postcode() . ']]></shipZip> <giftWrapped><![CDATA[' . $gift . ']]></giftWrapped> <shipVia>NotAvailable</shipVia> <box> <shipQty>' . $item["qty"] . '</shipQty> <sku><![CDATA[' . $_product->get_sku() . '_' . $item["pa_cardquantity"] . ']]></sku> <font><![CDATA[Unknown]]></font> <substrate><![CDATA[Unknown]]></substrate> <boxType><![CDATA[' . $item["pa_boxtype"]; if (strlen($item["pa_boxcolor"]) > 0) { $xmlstring .= '-' . $item["pa_boxcolor"]; } $xmlstring .= ']]></boxType>'; $sentiment_results = $wpdb->get_results("SELECT * FROM sentiments WHERE approved = 1 AND PID = " . $PID, ARRAY_A); // Start Card if ($sentiment_results) { foreach ($sentiment_results as $row) { $xmlstring .= ' <card> <note><![CDATA[' . $row["sentiment_text"] . ']]></note> <author><![CDATA[' . $row["sentiment_name"] . ']]></author> <image><![CDATA[' . $item["pa_cardcolor"] . ']]></image> </card>'; $blankcolor = $item["pa_cardcolor"]; } } // End Card $order_count++; // Increase Count } // Extra Cards for ($i = 0; $i < $extracards; $i++) { $xmlstring .= ' <card> <note><![CDATA[]]></note> <author><![CDATA[]]></author> <image><![CDATA[' . $blankcolor . ']]></image> </card>'; } // End Extra Cards $xmlstring .= ' </box>'; // Close Box } // Close Order $xmlstring .= ' </order>'; // Save File $file = $order_id . '.xml'; file_put_contents('orderlist/' . $file, $xmlstring); $response = sftp_printer($file); //echo '<script>window.alert("HELLO -- '.$order_id.' -- '.$response.'");</script>'; }
/** * Creates a customer in the tests DB. */ public static function create_customer($username = '******', $password = '******', $email = '*****@*****.**') { $customer = new WC_Customer(); $customer->set_billing_country('US'); $customer->set_first_name('Justin'); $customer->set_billing_state('PA'); $customer->set_billing_postcode('19123'); $customer->set_billing_city('Philadelphia'); $customer->set_billing_address('123 South Street'); $customer->set_billing_address_2('Apt 1'); $customer->set_shipping_country('US'); $customer->set_shipping_state('PA'); $customer->set_shipping_postcode('19123'); $customer->set_shipping_city('Philadelphia'); $customer->set_shipping_address('123 South Street'); $customer->set_shipping_address_2('Apt 1'); $customer->set_username($username); $customer->set_password($password); $customer->set_email($email); $customer->create(); return $customer; }