www.webdeveloper.com
Results 1 to 9 of 9

Thread: Turn invoice into event ticket

  1. #1
    Join Date
    Jun 2013
    Posts
    7

    Turn invoice into event ticket

    I am trying to use a Wordpress module called WooCommerce PDF Invoices to make event tickets by modifying the layout of the invoice to create an online ticket to printout. I've successful reformatted the layout and it works like a charm except for one thing.

    The problem I have is that no matter what is bought the invoice reads "This is a ticket" which I hardcoded into the invoice design. What I would like is an if/then statement inserted into the invoice design that will print between "This is a ticket" or "This is a receipt" depending on if they purchase one of the 4 ticket items. Is this possible? If so, can anyone give me a direction to find the coding for this?

    If ticket 1 then print "This is a ticket"
    else print "This is a receipt.
    If ticket 2 then print "This is a ticket"
    else print "This is a receipt.
    If ticket 3 then print "This is a ticket"
    else print "This is a receipt.
    If ticket 4 then print "This is a ticket"
    all else print "This is a receipt.

    Can anybody give me an idea how to write this in php. I'm a pro at html but I've only taught myself how to modify existing php coding. I can't write it from scratch. Any help is appreciated.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    897
    I'll take a stab at your problem.

    Somewhere in your php code where that statement is being produced/printed use this instead:
    PHP Code:
    switch  ($item)
    {
        case 
    "item1name":  
            
    $item_title "This is item 1";
            break;
        case 
    "item2name":  
            
    $item_title "This is item 2";
            break;
        case 
    "item3name":  
            
    $item_title "This is item 3";
            break;
        case 
    "item4name":  
            
    $item_title "This is item 4";
            break;

    This code will evaluate your incoming code ($item) and create the desired label from it that you want to show on your output ($item_title). Now you just have to place $item_title where you are currently outputting your hard-coded value.

  3. #3
    Join Date
    Jun 2013
    Posts
    7
    Thank you for your reply. I worked with this code over the weekend but don't think it will accomplish what I need. So I took the rest of the weekend and completely redesigned the invoice to look like an online ticket. The first half looks like an actual ticket.
    <?php global $wpo_wcpdf; ?>
    <table align="center" cellpadding="0" cellspacing="0" class="pdfbackground" style="width: 700px; height: 350px">
    <tr>
    <td style="width: 20px">&nbsp;</td>
    <td style="width: 285px">&nbsp;</td>
    <td style="width: 300px">&nbsp;</td>
    <td style="width: 75px">&nbsp;</td>
    <td style="width: 20px">&nbsp;</td>
    </tr>
    <tr>
    <td rowspan="4" style="width: 20px">&nbsp;</td>
    <td class="pdflogo" rowspan="4" style="width: 285px"><br /><div id="container"><div><?php
    if( $wpo_wcpdf->get_header_logo_id() ) {
    $wpo_wcpdf->header_logo();
    } else {
    _e( 'Ticket', 'wpo_wcpdf' );
    }
    ?></div><div class="order-information">
    <br /><br /><hr width=50% color=#0087E1><?php
    $date_setting = isset($wpo_wcpdf->settings->template_settings['display_date'])?$wpo_wcpdf->settings->template_settings['display_date']:'order_date';
    $number_setting = isset($wpo_wcpdf->settings->template_settings['display_number'])?$wpo_wcpdf->settings->template_settings['display_number']:'order_number';

    // set $display date & label to user setting
    if ( $date_setting == 'invoice_date' ) {
    $display_date = $wpo_wcpdf->get_invoice_date();
    $display_date_label = __( 'Event Date:', 'wpo_wcpdf' );
    } else {
    $display_date = $wpo_wcpdf->get_order_date();
    $display_date_label = __( 'Order Date:', 'wpo_wcpdf' );
    }

    // set $display number & label to user setting
    if ( $number_setting == 'invoice_number' ) {
    $display_number = $wpo_wcpdf->get_invoice_number();
    $display_number_label = __( 'Ticket Number:', 'wpo_wcpdf' );
    } else {
    $display_number = $wpo_wcpdf->get_order_number();
    $display_number_label = __( 'Order Number:', 'wpo_wcpdf' );
    }
    ?>
    <span class="order-date-label"><?php echo $display_date_label; ?></span>
    <span class="order-date"><?php echo $display_date; ?></span><br />
    <span class="order-number-label"><?php echo $display_number_label; ?></span>
    <span class="order-number"><?php echo $display_number; ?></span><br />
    <br />
    <br />
    </div></div></td>
    <td style="width: 300px"><div class="shop-name"><h3><?php $wpo_wcpdf->shop_name(); ?></h3><br /> SPONSORED BY: <br />SPONSOR 1 LOGO | SPONSOR 2 LOGO </div>
    </td>
    <td rowspan="4" style="width: 75"><br /><br /><br /><br /><br /><br />
    <img alt="" height="126" src="http://www.3corlando.com/wp-content/uploads/2014/06/barcode.png" width="71" class="barcode" /></td>
    <td rowspan="4" style="width: 20px">&nbsp;</td>
    </tr>
    <tr>
    <td style="width: 300px"><hr width=75% color=#0087E1><div class="shop-address"><?php $wpo_wcpdf->shop_address(); ?></div>
    </td>
    </tr>
    <tr>
    <td style="width: 300px">
    </td>
    </tr>
    <tr>
    <td style="width: 300px"></td>
    </tr>
    <tr>
    <td class="pdfborder" style="width: 20px">&nbsp;</td>
    <td class="pdfvoid" colspan="3"><div class="pdfvoid"><hr width=50% color=#0087E1>***This is a Receipt***
    </div>
    </td>
    <td class="pdfborder" style="width: 20px">&nbsp;</td>
    </tr>
    </table>
    And the second half looks like an invoice.
    <!-- head container -->
    <hr>
    <table class="order-details">
    <thead>
    <tr>
    <th class="product-label"><?php _e('Shop Items', 'wpo_wcpdf'); ?></th>
    <th class="quantity-label"><?php _e('Quantity', 'wpo_wcpdf'); ?></th>
    <th class="price-label"><?php _e('Price', 'wpo_wcpdf'); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item ) : ?><tr>
    <td class="description">
    <?php $description_label = __( 'Description', 'wpo_wcpdf' ); // registering alternate label translation ?>
    <span class="item-name"><?php echo $item['name']; ?></span><span class="item-meta"><?php echo $item['meta']; ?></span>
    <dl class="meta">
    <?php if( !empty( $item['sku'] ) ) : ?><dt><?php _e( 'SKU:', 'wpo_wcpdf' ); ?></dt><dd><?php echo $item['sku']; ?></dd><?php endif; ?>
    <?php if( !empty( $item['weight'] ) ) : ?><dt><?php _e( 'Weight:', 'wpo_wcpdf' ); ?></dt><dd><?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif; ?>
    </dl>
    </td>
    <td class="quantity"><?php echo $item['quantity']; ?></td>
    <td class="price"><?php echo $item['order_price']; ?></td>
    </tr><?php endforeach; endif; ?>
    </tbody>
    <tfoot>
    <tr class="no-borders">
    <td class="no-borders" colspan="3">
    <table class="totals">
    <tfoot>
    <?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $total ) : ?>
    <tr>
    <td class="no-borders">&nbsp;</td>
    <th class="description"><?php echo $total['label']; ?></th>
    <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
    </tr>
    <?php endforeach; ?>
    </tfoot>
    </table>
    </td>

    </tr>
    </tfoot>
    </table><!-- order-details -->

    <table class="notes container">
    <tr>
    <td colspan="3">
    <div class="notes-shipping">
    <?php if ( $wpo_wcpdf->get_shipping_notes() ) : ?>
    <h3><?php _e( 'Customer Notes', 'wpo_wcpdf' ); ?></h3>
    <?php $wpo_wcpdf->shipping_notes(); ?>
    <?php endif; ?>
    </div>
    </td>
    </tr>
    </table><!-- notes container -->


    <?php if ( $wpo_wcpdf->get_footer() ): ?>
    <div id="footer">
    <?php $wpo_wcpdf->footer(); ?>
    </div><!-- #letter-footer -->
    <?php endif; ?>
    I want to identify a ticket item in the second half where the invoice prints the items and change the "This is a receipt" in the first half to "This is a ticket." I believe having "receipt as default would be easier since I have a lot of products but only 4 tickets. So the if/then would only apply if one of the 4 tickets are printed on the pdf.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    897
    Sorry - I don't feel like getting a headache trying to read and interpret whatever it is you are doing. Your convoluted mixture of html and php is to be avoided at all costs and yours is just a wreck to read.

  5. #5
    Join Date
    Jun 2013
    Posts
    7
    I'm sorry. Once again I state that I'm a html programmer so i don't know any other way of doing this.
    So allow me to clarify without using the html coding. First I'll show the pdf invoice.
    http://www.3corlando.com/pdf-invoice.gif

    Next I'll show a sample of what I'm trying to accomplish.

    INVOICE TOP
    This is a receipt
    ====================
    INVOICE BOTTOM
    Item Price Total
    Ticket $200 $200

    When ticket items show up in bottom of invoice I want to change "This is a receipt" at top of invoice to "This is a ticket."

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    897
    Well, I'm sure you already know (as an html user) that it is simply a presentation (markup) language and provides no logic (ie, programming) abilities. Hence nothing you can do. But since the code you are posting is using php there is a solution (which I provided a template for) which you could use with a little work on your part.

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,514
    Can I suggest something that might be simpler.

    Produce a graphic of a ticket, how you want it to look, you then use the GD library of PHP to write in the missing elements that you need adding to the ticket such as dates & security elements like a 2d (QR) barcode or code39 bar code.

    Then take that image and insert it in to a PDF file and output your invoice for the ticket at the same time.

    You can use the same process for the invoice, make an image template that you then add in the text and values as needed.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Jun 2013
    Posts
    7
    That shows you how much I'll know, I didn't event know image creation was possible through PHP. I'll definitely check into it. I got this code from another forum that I might use also.

    PHP Code:
    if($items['property_name']=='value_to_identify_ticket')
    {
        
    $title "This is a ticket";
    }
    else
    {
        
    $title "This is an invoice";
    }
    //Use title in the code to generate the output 

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,514
    http://www.php.net/manual/en/ref.image.php

    You will need to check that the GD library is installed on the server, if it isn't then get the server admin to install it, its a case of download the library or in many cases a simple option to switch on in the server (assuming its a linux machine)
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles