Can't output billing address when not using get_address

Viewed 25

i'm using woocommerce wordpress. I have a question.

How to show billing address with get_address but in state output not abbreviated. Because i can't use get_formatted_billing_address to show the output.

The output without get_product function (using get_formatted_billing_address)

The output with get_product function (but the state get abbreviated)

The state in here is 'JI' instead of 'Jawa Timur'

How to get full name state output?

*Edited This is the code. The billing code is in the end of code. Thanks

public function lw_order_info_whatsapp()
        {
            
            $this->load_textdomain();
            // data preparations for order
            $order_id = wc_get_order_id_by_order_key($_GET['key']);
            $order = wc_get_order($order_id);
            $orderDate = wc_format_datetime($order->get_date_created());
            $email = $order->get_billing_email();
            $orderCurrency = $order->get_currency();
            $orderCurrencySymbol = get_woocommerce_currency_symbol($orderCurrency);
            $paymentUrl = $order->get_checkout_payment_url();
            // total formatting
            $totalAmount = $orderCurrencySymbol . '' . $order->get_total() . ' ' . $orderCurrency;
            // whatsapp number where we need to send order
            $vendorWhatsAppNumber = $this->whatsapp_number;
            // get the order item
            $order_items = $order->get_items();
            // order details container
            $orderDetails = '';
            // loop through the each item
            foreach ($order_items as $index => $item) {
                // get product item
                $product = $item->get_product();
                // if product not found
                if (!$product) {
                    continue;
                }
                // list up the item
                $orderDetails .= <<<EOT
{$product->get_name()} x {$item->get_quantity()} => $orderCurrencySymbol{$item->get_subtotal()} $orderCurrency\n
EOT;
                foreach ($item->get_formatted_meta_data() as $itemMeta) {
                    $orderDetails .= strip_tags($itemMeta->display_key) . ': ' . strip_tags($itemMeta->display_value) . "\n";
                }
            }
            // list up the totals
            $orderDetails .= <<<EOT
\n--------------------------------\n
EOT;
            foreach ($order->get_order_item_totals() as $key => $total) {
                $itemValue = strip_tags(('payment_method' === $key) ? esc_html($total['value']) : wp_kses_post($total['value']));
                if (('payment_method' === $key)) {
                    continue;
                }
                $orderDetails .= <<<EOT

{$total['label']} $itemValue
EOT;
            }
            $orderDetails .= "\n\n--------------------------------\n\n";
            // if has customer note
            if ($order->get_customer_note()) {
                $orderDetails .=  esc_html(__('Note:', 'lwc-whatsapp-order')) . "\n";
                $orderDetails .=  wp_kses_post(nl2br(wptexturize($order->get_customer_note()))) . "\n";
            }
            // check if needs to show shipping
            $show_shipping = !wc_ship_to_billing_address_only() && $order->needs_shipping_address();
            // billing detail
            $orderDetails .=  esc_html(__('Billing address:', 'lwc-whatsapp-order')) . "\n\n";
            $orderDetails .= esc_html(implode("\n", $order->get_address())) . "\n";
0 Answers
Related