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.

"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]<?php global $wpo_wcpdf; ?>

         
 
<?php if( $wpo_wcpdf->get_header_logo_id() ) { $wpo_wcpdf->header_logo(); } else { _e( 'Ticket', 'wpo_wcpdf' ); } ?>



<?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’ );
}
?>
<?php echo $display_date_label; ?>
<?php echo $display_date; ?>

<?php echo $display_number_label; ?>
<?php echo $display_number; ?>




<?php $wpo_wcpdf->shop_name(); ?>


SPONSORED BY:
SPONSOR 1 LOGO | SPONSOR 2 LOGO






 

<?php $wpo_wcpdf->shop_address(); ?>
 

***This is a Receipt***
 
[/php] And the second half looks like an invoice. [php]
<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item ) : ?><?php endforeach; endif; ?>
<?php _e('Shop Items', 'wpo_wcpdf'); ?> <?php _e('Quantity', 'wpo_wcpdf'); ?> <?php _e('Price', 'wpo_wcpdf'); ?>
<?php $description_label = __( 'Description', 'wpo_wcpdf' ); // registering alternate label translation ?> <?php echo $item['name']; ?><?php echo $item['meta']; ?>
<?php if( !empty( $item['sku'] ) ) : ?>
<?php _e( 'SKU:', 'wpo_wcpdf' ); ?>
<?php echo $item['sku']; ?>
<?php endif; ?> <?php if( !empty( $item['weight'] ) ) : ?>
<?php _e( 'Weight:', 'wpo_wcpdf' ); ?>
<?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?>
<?php endif; ?>
<?php echo $item['quantity']; ?> <?php echo $item['order_price']; ?>
<?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $total ) : ?> <?php endforeach; ?>
  <?php echo $total['label']; ?> <?php echo $total['value']; ?>
<?php if ( $wpo_wcpdf->get_shipping_notes() ) : ?>

<?php _e( 'Customer Notes', 'wpo_wcpdf' ); ?>

<?php $wpo_wcpdf->shipping_notes(); ?> <?php endif; ?>
<?php if ( $wpo_wcpdf->get_footer() ): ?>
<?php $wpo_wcpdf->footer(); ?>
<?php endif; ?>[/php]

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.

I think you need to use the same logic you have in the bottom…

[php]<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item ) : ?>


[/php]

I guess you will use of these to determine, if it’s one of your 4 items…

[php]$item[‘name’]
$item[‘sku’][/php]

I didn’t test this, but it would look something similar to this.

Change this:

[php]This is a Receipt[/php]

To:
[php]

<?php $printticket = false; $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if ($item['name'] === 'Ticket Item') { $printticket = true; }; }; if ($printticket) { echo '***This is a Ticket***';} else {"***This is a Receipt***"}; ?>

[/php]

First let me show my appreciation for your response and help. I’ve posted this on wordpress support and the module support page and didn’t even get a response on either. Your solution is the closest I’ve gotten to getting this to work.

I added your code to the template invoice.php but got an error message:

Parse error: syntax error, unexpected '}' in ../wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Ticket/invoice.php on line 125

I completely take responsibility that I might be doing something wrong. Am I suppose to set the range of the ticket item names?

And would using the sku be easier? I don’t assign my products sku numbers so I could give each of the 4 ticket items a sku so if a sku prints its automatically recognized as a ticket item.

The tickets are: "Masquerade Ball Ticket (Bronze)" sku MBBRNZTIX "Masquerade Ball Ticket (Silver)" sku MBSLVRTIX "Masquerade Ball Ticket (Gold)" sku MBGOLDTIX "Masquerade Ball Ticket (Platinum)" sku MBPLATTIX.
Let me know if this helps.

My bad, I missed a “}” bracket, I always do that. Below is the correct code. If you want to use SKU numbers that’s fine too.

[php] <?php
$printticket = false;
$items = $wpo_wcpdf->get_order_items();
if( sizeof( $items ) > 0 ) {
foreach( $items as $item )
{
if (($item[‘sku’] === ‘MBBRNZTIX’) || ($item[‘sku’] === ‘MBSLVRTIX’) || ($item[‘sku’] === ‘MBGOLDTIX’) ||($item[‘sku’] === ‘MBPLATTIX’)) { $printticket = true; };
};
};
if ($printticket) { echo ‘This is a Ticket’;} else {“This is a Receipt”}; ?>[/php]

I definitely think the skus will work better.

But I went over this new coding with the skus for about an hour and I’m still getting the same error message.

Parse error: syntax error, unexpected '}' in .../wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Ticket/invoice.php on line 126

There is either a bracket missing or one too many. I can’t seem to find out which one it is.

We are so close. I’m going to go back and repost the final solution on the wordpress module support page once we get it this working properly. And I’ll make sure to give you all the credit.

repost the modified code

i didn’t modify anything. I posted it as is and got the error. I tried to find the error myself with no success. There are two open brackets on line 4 and line 6 which doesn’t seem right but what do I know… I’m still learning.

[php]<?php
$printticket = false;
$items = $wpo_wcpdf->get_order_items();
if( sizeof( $items ) > 0 ) {
foreach( $items as $item )
{
if (($item[‘sku’] === ‘MBBRNZTIX’) || ($item[‘sku’] === ‘MBSLVRTIX’) || ($item[‘sku’] === ‘MBGOLDTIX’) ||($item[‘sku’] === ‘MBPLATTIX’)) { $printticket = true; };
};
};
if ($printticket) { echo ‘This is a Ticket’;} else {“This is a Receipt”}; ?>[/php]

I meant post that code, inside of the bigger piece you modified. I want to see where line 126 falls.

Duh!! :-X Sorry about that. I wasn’t understanding. I wanted to test the code out before I went through the trouble of reformating anything. So I put it after the invoice table @.

[php]<?php global $wpo_wcpdf; ?>

         
 
<?php if( $wpo_wcpdf->get_header_logo_id() ) { $wpo_wcpdf->header_logo(); } else { _e( 'Ticket', 'wpo_wcpdf' ); } ?>



<?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>






 

<?php $wpo_wcpdf->shop_address(); ?>
 

***This is a Ticket***
This ticket is non-transferable, non-refundable, and void if modified.
 

<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item ) : ?><?php endforeach; endif; ?>
	</tr>
</tfoot>
<?php _e('Shop Items', 'wpo_wcpdf'); ?> <?php _e('Quantity', 'wpo_wcpdf'); ?> <?php _e('Price', 'wpo_wcpdf'); ?>
<?php $description_label = __( 'Description', 'wpo_wcpdf' ); // registering alternate label translation ?> <?php echo $item['name']; ?><?php echo $item['meta']; ?>
<?php if( !empty( $item['sku'] ) ) : ?>
<?php _e( 'SKU:', 'wpo_wcpdf' ); ?>
<?php echo $item['sku']; ?>
<?php endif; ?> <?php if( !empty( $item['weight'] ) ) : ?>
<?php _e( 'Weight:', 'wpo_wcpdf' ); ?>
<?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?>
<?php endif; ?>
<?php echo $item['quantity']; ?> <?php echo $item['order_price']; ?>
<?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $total ) : ?> <?php endforeach; ?>
  <?php echo $total['label']; ?> <?php echo $total['value']; ?>
<?php $printticket = false; $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if (($item['sku'] === 'MBBRNZTIX') || ($item['sku'] === 'MBSLVRTIX') || ($item['sku'] === 'MBGOLDTIX') ||($item['sku'] === 'MBPLATTIX')) { $printticket = true; }; }; }; if ($printticket) { echo '***This is a Ticket***';} else {"***This is a Receipt***"}; ?>
<?php if ( $wpo_wcpdf->get_shipping_notes() ) : ?>

<?php _e( 'Customer Notes', 'wpo_wcpdf' ); ?>

<?php $wpo_wcpdf->shipping_notes(); ?> <?php endif; ?>
<?php if ( $wpo_wcpdf->get_footer() ): ?>
<?php $wpo_wcpdf->footer(); ?>
<?php endif; ?>[/php]

Put the word

echo before “this is a receipt”

And a ; after it.

You are the man! It works perfectly.
And you taught me a lot by patiently going over this with me.
Thank you.

And I’m sure all who will read the post on the module page thank you also.

Awesome, happy it worked for you. If I didn’t make any coding errors, we would of got it right on the first try.

Sponsor our Newsletter | Privacy Policy | Terms of Service