Add Ticket Barcodes to WooCommerce Box Office Emails

WooCommerce has an extension called Box Office that can be used to sell tickets on your store. We originally created it to run WooConf 2016.

WooCommerce Box Office and Order Barcodes work together and can give people purchasing tickets on your site, barcodes that you can use to verify admission. It’s a good system that allows anyone to quickly verify tickets.

One problem that people run into is the barcodes for the tickets are only available inside the person’s account. They have to be viewed and printed on the website. I recently had a user who was looking to include the order barcodes on the order emails. Here’s the solution that she came up with.

First create a folder in your theme or child theme called woocommerce-box-office. We can use this folder as a place to create overrides for the Box Office templates.

Then inside this folder, create another folder called order. Then copy the order-tickets.php file out of the woocommerce-box-office/templates/order/ folder in the plugin and place it into the new directory in your theme. The path in your theme should be /woocommerce-box-office/order/order-tickets.php.

Next we want to modify this section:

<dl class="purchased-tickets">
	<?php foreach ( $tickets as $ticket ) : ?>
		<dt>
			<a href="<?php echo esc_url( wcbo_get_my_ticket_url( $ticket->ID ) ); ?>">
				<?php echo esc_html( $ticket->post_title ); ?>
			</a>
			<?php if ( 'pending' === $ticket->post_status ) : ?>
				&mdash;
				<span class="pending"><?php _e( 'Pending', 'woocommerce-box-office' ); ?></span>
			<?php endif; ?>
		</dt>
		<dd class="description">
			<?php echo wc_box_office_get_ticket_description( $ticket->ID, $fields_format ); ?>
		</dd>
	<?php endforeach; ?>
</dl>

so that it will be like this:

<dl class="purchased-tickets">
<?php foreach ( $tickets as $ticket ) : ?>
<dt>
<a href="<?php echo esc_url( wcbo_get_my_ticket_url( $ticket->ID ) ); ?>">
<?php echo esc_html( $ticket->post_title ); ?>
</a>
<?php if ( 'pending' === $ticket->post_status ) : ?>
&mdash;
<span class="pending"><?php _e( 'Pending', 'woocommerce-box-office' ); ?></span>
<?php endif; ?>
</dt>
<dd class="description">
<?php echo WC_Order_Barcodes()->display_barcode($ticket->ID); ?>
<?php echo wc_box_office_get_ticket_description( $ticket->ID, $fields_format ); ?>
</dd>
<?php endforeach; ?>
</dl>

Now when the email is set to the customer, it will have the barcode for each ticket in it. Here’s a screenshot from an order email.

You can also customize this further by modifying the email template, but this should get you started.

So now if you want to include the ticket barcodes in your customer emails, you can. If you have any questions, please let me know in the comments.


4 responses to “Add Ticket Barcodes to WooCommerce Box Office Emails”

  1. Medes Media Avatar

    Hey Bill,

    I enjoyed this read but how were you guys able to solve the issue of single orders with multiple ticket purchases?

    A client of ours is currently using WC Box Office + WC Order Barcodes but when a single customer buys multiple tickets for a group, with unique names & emails for those tickets, it only generates scannable barcodes for the Order, rather than the individual tickets on that Order that you can then checkin on the scan page as the ticketholders may not arrive as a group.

    Seems like a critical issue in the logic between WC Box Office + WC Order Barcodes handoff that I am certain you would have encountered at WooConf ’16.

    Your insights on this would be sincerely appreciated.

    Keep up the great work!

    1. Bill Robbins Avatar
      Bill Robbins

      Great question! As you’re aware, Order Barcodes only creates a single barcode to represent an order even if it has multiple unique tickets in it. The unique barcodes for each ticket are available within the user’s account section. They aren’t emailed by default.

      That was the idea behind the code snippets in this post. The user wanted to send these unique barcodes in the email instead of the main one for the order. If it still works as expected, it should do that for you. Let me know if you have any questions.

  2. Uriel Lopez Avatar
    Uriel Lopez

    I tried implementing this on my site but for some reason, the tickets are added to the email-but they are distorted and un-scannable, any idea of why this might be happening?

    1. Bill Avatar
      Bill

      It sounds like there may be a styling issue here that’s causing the links to be distorted. If this was my site, I would try changing the styling of the elements that surround the barcodes. Ideally, the height and width would be defined automatically instead of being forced into a specific size.

Leave a Reply

%d bloggers like this: