• Resolved wesitegeezer

    (@wesitegeezer)


    Hi Thanks for the great plugin

    I need to convert the order number to a string of letters to be echoed under the existing order number on the invoice and packing slip.

    So A=1 B=2 C=3
    order number #12345
    becomes ABCDE

    Is it possible?

    regards lee

    • This topic was modified 6 years, 6 months ago by wesitegeezer.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    Yes that is possible with a small code snippet. Try this:

    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_order_number_letters', 10, 2 );
    function wpo_wcpdf_order_number_letters ( $template_type, $order ) {
        if ( method_exists($order, 'get_order_number')) {
    	    $order_number = $order->get_order_number();
    	    $order_code = str_replace( str_split('1234567890'), str_split('ABCDEFGHIJ'), $order_number);
            ?>
            <tr class="order-number-letters">
                <th>Order Code:</th>
                <td><?php echo $order_code; ?></td>
            </tr>
            <?php
        }
    }
    

    Hope that helps!

    Thread Starter wesitegeezer

    (@wesitegeezer)

    Hi Thanks for quick reply, could not get that to work… but got this working in the end. Needed a GDPR anon lable printed to attach to order in letters not numeric. below works if anyone else needs

    
    add_action( 'wpo_wcpdf_before_order_data', 'wpo_wcpdf_customer_number', 10, 2 );
    function wpo_wcpdf_customer_number ($template_type, $order) {
    $numarr=array('A' => 0,
    'B' => 1,
    'C' => 2,
    'D' => 3,
    'E' => 4,
    'F' => 5,
    'G' => 6,
    'H' => 7,
    'I' => 8,
    'J' => 9);
    $narr = array_flip($numarr);
    $order_id = $order->get_id();
    $arr = str_split($order_id);
     
    $str = '';
    foreach($arr as $s)
       $str .= $narr[$s];
        ?>
    <div>
       <h2>Customer REF:</h2>
       <h1><?php echo $str . "\n"; ?></h1>
       </div>
        <?php
    }
    • This reply was modified 6 years, 6 months ago by wesitegeezer.
    • This reply was modified 6 years, 6 months ago by wesitegeezer.
    Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    Glad to hear that works for you! I’m not sure why my snippet didn’t work for you, I tested it on my own site and it worked fine. Did you get any errors?

    Either way I’m glad to hear the issue is resolved but would love to know why it didn’t work for you!

    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Convert Order Number to Letters’ is closed to new replies.