get_shipping_address() public method

Get shipping_address_1.
public get_shipping_address ( string $context = 'view' ) : string
$context string
return string
Beispiel #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>';
}
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>';
}