• Resolved zaja

    (@zaja)


    I need to create separate table/area on the order-details.php with order data formated in specific way. (existing content of the order details page does not need to be modified, this should be shown as an addition).
    The goal is to create a PDF417 barcode image on order page, so customer can quickly scan and make bank payment.

    1. How to display customer billing address in this format?

    FIRSTNAME SECONDNAME
    STREETNAME NUMBER
    POSTALCODE CITY

    2. To generate a barcode, I need to show the price as a 15-digit number, without a comma. The price should be aligned on the right, the remaining seats up to 15 must be filled with zero to the left. Examples:

    123,55 must be displayed as 000000000012355
    1298,99 must be displayed as 000000000129899
Viewing 4 replies - 1 through 4 (of 4 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    1) Can use the woocommerce_order_formatted_billing_address and woocommerce_order_formatted_shipping_address filters to customize the output of the address.

    2) You’re looking to leftpad. This function will help: https://php.net/manual/en/function.str-pad.php

    Thread Starter zaja

    (@zaja)

    Great, thanks…this work fine, except that I don’t know how to remove decimal separator from price/number:

    <?php echo str_pad($order->get_total(), 15, "0", STR_PAD_LEFT); ?>

    Do you have any idea how to remove it?

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    How about multiplying the order total by 100 before applying the pad? Like:

    
    <?php 
    $total_no_decimals = 100 * $order->get_total();
    echo str_pad($total_no_decimals, 15, "0", STR_PAD_LEFT); ?>
    

    I just checked this in PHP Sandbox and this should do the trick.

    Thread Starter zaja

    (@zaja)

    Thank you, I’vused this code, it works fine:
    <?php echo str_pad(preg_replace('/\./', '', $order->get_total()), 15, "0", STR_PAD_LEFT); ?>

    btw. I have tested your code, it works fine. ??

    • This reply was modified 6 years, 9 months ago by zaja.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom order/address data on orders-details.php’ is closed to new replies.