I am wanting to customize the customer-completed-order.php
template in WooCommerce Bookings and would like to add a line like the following.
Your session will take place on May 11, 2020, 7:00 pm in timezone: Asia/Tokyo. If this time is incorrect please let us know so we can help you to reschedule.
I would like to replace the May 11, 2020, 7:00 pm in timezone: Asia/Tokyo
with the actual booking time/date. This is displayed automatically in the original email and it looks like it relies on the booking-summary-list.php
file but I cannot seem to just pick out the time and date to display that how I would like.
I am very much a beginner with PHP so still trying to figure out how this all pieces together. I believe the following two sources could be of help as well.
https://www.thathandsomebeardedguy.com/retrieve-booking-meta-data
WooCommerce Booking email template
https://docs.woocommerce.com/document/bookings-snippets
Could I write a function sort of like the following that I could just add to that customer-completed-order.php
file? This is currently not working at all. I believe the $order
that I am passing in is possibly not needed or is not correct. The would also need to be put in the actual time/date line but I have left it as it is for the moment to see the whole function and call together.
<?php
function get_order_print_date($order) {
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order );
foreach ( $booking_ids as $booking_id ) {
$booking = new WC_Booking( $booking_id );
///this is where I get stuck and cannot get the information I need
}
}
?>
<?php get_order_print_date() ?>
I'll include the entire file so far that I have edited so far so you can get a better idea of what I have hacked together so far. Again, super beginner so would really appreciate any help!
<?php
/**
* Customer completed order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates/Emails
* @version 3.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer first name */ ?>
<p>
<?php printf(
esc_html__( 'Hi there,', 'woocommerce' )
); ?>
</p>
<?php
function get_order_print_date($order) {
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order );
foreach ( $booking_ids as $booking_id ) {
$booking = new WC_Booking( $booking_id );
///pick out just the booking time and date
}
}
?>
<?php get_order_print_date() ?>
<?php /* translators: %s: Site title */ ?>
<p>Your payment has been recieved and your session has been successfully booked! Thank you. We are super excited for the chance to share in your adventure.</p>
<h2>Survey</h2>
<p>To make sure we are prepared to be the best teachers possible, please take the time to fill out the survey linked below to give us some necessary background information on your trip.</p>
<p><a class="crashcourse_email_button" href="https://forms.gle/ujhfP3P9vyHFUWhB6">Travel Planning Survey → </a></p>
<h2>Session</h2>
<p>Your session will take place at 8:15am America/Denver time. If this time is incorrect please let us know so we can help you to reschedule.</p>
<?php
/*
* @hooked WC_Emails::order_details() Shows the order details table.
* @hooked WC_Structured_Data::generate_order_data() Generates structured data.
* @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* @since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
/*
* @hooked WC_Emails::order_meta() Shows order meta data.
*/
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
/*
* @hooked WC_Emails::customer_details() Shows customer details
* @hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
/**
* Show user-defined additonal content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
Any help would be very helpful.