get_shipping_postcode() public method

Get shipping_postcode.
public get_shipping_postcode ( string $context = 'view' ) : string
$context string
return string
Exemplo n.º 1
0
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>';
}
 /**
  * Prepare a single customer output for response.
  *
  * @param WP_User           $user_data User object.
  * @param WP_REST_Request   $request   Request object.
  * @return WP_REST_Response $response  Response data.
  */
 public function prepare_item_for_response($user_data, $request)
 {
     $customer = new WC_Customer($user_data->ID);
     $last_order_data = $customer->get_last_order();
     $last_order = null;
     if ($last_order_data) {
         $last_order = array('id' => $last_order_data->get_id(), 'date' => wc_rest_prepare_date_response($last_order_data->get_date_created()));
     }
     $data = array('id' => $customer->get_id(), 'date_created' => wc_rest_prepare_date_response(date('Y-m-d H:i:s', $customer->get_date_created())), 'date_modified' => $customer->get_date_modified() ? wc_rest_prepare_date_response(date('Y-m-d H:i:s', $customer->get_date_modified())) : null, 'email' => $customer->get_email(), 'first_name' => $customer->get_first_name(), 'last_name' => $customer->get_last_name(), 'username' => $customer->get_username(), 'last_order' => $last_order, 'orders_count' => $customer->get_order_count(), 'total_spent' => $customer->get_total_spent(), 'avatar_url' => $customer->get_avatar_url(), 'billing' => 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' => 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()));
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($user_data));
     /**
      * Filter customer data returned from the REST API.
      *
      * @param WP_REST_Response $response   The response object.
      * @param WP_User          $user_data  User object used to create response.
      * @param WP_REST_Request  $request    Request object.
      */
     return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request);
 }
 /**
  * Get the customer for the given ID
  *
  * @since 2.1
  * @param int $id the customer ID
  * @param array $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(), 'role' => $customer->get_role(), '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));
 }
Exemplo n.º 4
-1
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>';
}