codefantom Posted July 7, 2014 Share Posted July 7, 2014 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. "This is a recept"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." I completely redesigned the woocommerce pdf 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"> </td> <td style="width: 285px"> </td> <td style="width: 300px"> </td> <td style="width: 75px"> </td> <td style="width: 20px"> </td> </tr> <tr> <td rowspan="4" style="width: 20px"> </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 = __( 'Transaction 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"> </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"> </td> <td class="pdfticket" colspan="3"><div class="pdfticket"><hr width=50% color=#0087E1>***This is a Receipt*** </div> </td> <td class="pdfborder" style="width: 20px"> </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"> </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 one of my 4 ticket items that may appear where the invoice prints the items and when one of them does appear it changes "This is a receipt" to "This is a ticket" in the first half. Is something like this possible? If so, can anyone give me a direction to find the coding for this? 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 7, 2014 Share Posted July 7, 2014 (edited) I guess I'm not following. I don't see anything in the two code sections you posted with "This is a ticket" hard-coded. You state you only want to change the "This is a ticket" text based on the product ordered. But, then you provide two different code sections: one for a ticket and one for an invoice. So, I'm not sure if you just want to change that text or if you are wanting to select one of the two sections of code based on the order. Plus, I don't know if it is possible for a person to buy multiple things in an order and what you expect in that situation. So, I can only provide some very general advice. Assuming these products are in a database, I would have a property for the products to identify if they are a ticket or not. You may already have this. So, when you query the product details to display an invoice/ticket, include that property. Then use that property to display the right title. 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 This is the best option since you only need to edit the product details when managing the products. You should never have to touch the code. However, if for some reason this isn't possible you would have to create code to check what product is being produced. This is problematic as you would have to edit the code to support more products. There are many ways to accomplish this, but a switch() would probably be easiest. You would want to use some value associated with the products which is unique such as a product ID or name. switch($items['id']) { case 'ticket1ID': case 'ticket2ID': case 'ticket3ID': case 'ticket4ID': $title = "This is a ticket"; break; default: $title = "This is an invoice"; break; } Edited July 7, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
codefantom Posted July 7, 2014 Author Share Posted July 7, 2014 Sorry, I did some last minute mods to the php file. So to clarify I decided to show you how the pdf invoice looks. The 4 tickets will appear as: Masquerade Ball Ticket (Bronze) Masquerade Ball Ticket (Silver) Masquerade Ball Ticket (Gold) Masquerade Ball Ticket (Plantinum) So if I decided to try the first option, would this be correct? if($items['Masquerade Ball Ticket']=='ticket') { $title = "This is a ticket"; } else { $title = "This is an invoice"; } //Use title in the code to generate the output And is there a specific location that I have to put the code for it to work? Or do I put it where I want the output to appear? Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 7, 2014 Share Posted July 7, 2014 So if I decided to try the first option, would this be correct? . . . And is there a specific location that I have to put the code for it to work? Or do I put it where I want the output to appear? I can answer neither of those questions. I don't have enough understanding of the data structure or the logic of your code. And, I am not going to invest the time to obtain either. I stated pretty clearly in my first response that I was only providing very general advice. if($items['Masquerade Ball Ticket']=='ticket') So, are you saying ALL items have a property called 'Masquerade Ball Ticket' and that it has a value of 'ticket' if they are a ticket type of product? If so, that would likely work. But, I'm guessing that 'Masquerade Ball Ticket' is more likely a VALUE that some products have. E.g. $items['product_name'] = 'Masquerade Ball Ticket'. Why would all products have a property called 'Masquerade Ball Ticket'? As I stated, the correct way to do this is to have a property for all your products that lets you identify which one's are tickets and which ones are not. If you can't do that, then you will need to check the individual products in the code (my second example) which is a far less preferred solution. As for where it goes, that's up to you. You already stated you hard-coded the message for "This is a ticket". So, somewhere before that line is executed you need to make a decision as to what the text should be. It could be in the code to produce the invoice or before you call that code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.