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.
I was able to solve this by doing the following two steps. Hopefully this is helpful if anyone else has this issue in the future.
First, I added the following function to my functions.php file.
function crashcourse_booking_time($order){
$items = $order->get_items();
foreach( $items as $item ) {
$booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_item_id( $item->get_id() );
foreach( $booking_ids as $booking_id ) {
$booking = new WC_Booking($booking_id);
$get_local_time = wc_should_convert_timezone( $booking );
if ( strtotime( 'midnight', $booking->get_start() ) === strtotime( 'midnight', $booking->get_end() ) ) {
$booking_date = sprintf( '%1$s', $booking->get_start_date( null, null, $get_local_time ) );
} else {
$booking_date = sprintf( '%1$s / %2$s', $booking->get_start_date( null, null, $get_local_time ), $booking->get_end_date( null, null, $get_local_time ) );
}
echo esc_html( apply_filters( 'wc_bookings_summary_list_date', $booking_date, $booking->get_start(), $booking->get_end() ) );
$booking_timezone = str_replace( '_', ' ', $booking->get_local_timezone() );
if ( wc_should_convert_timezone( $booking ) ):
echo esc_html( sprintf( __( ' in timezone: %s', 'woocommerce-bookings' ), $booking_timezone ) );
endif;
}break;
}
}
Then in my actual file booking-summary-list.php I was able to just call the function.
<p>We'll be meeting on <?php crashcourse_booking_time($order); ?> for your upcoming lesson. Let us know as soon as possible of any discrepancy so we can get your session rescheduled.</p>
Cheers!
Related
I need to remove the following from the Customer Processing Order email that WooCommerce sends customers once they have placed an order:
Payment Type
Price of items purchased
Everything that sits within the table below the items purchased, i.e. Total and Notes.
I've attached an image for a visual look at what needs ot be removed from the email:
items to be removed:
The file is found here: yourtheme/woocommerce/emails/customer-processing-order.php and it contains the code below but as you can see it's not a simple case of remove or comment out sections.:
<?php
/**
* Customer processing order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-processing-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 %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Order number */ ?>
<p><?php printf( esc_html__( 'Just to let you know — we\'ve received your order #%s, and it is now being processed:', 'woocommerce' ), esc_html( $order->get_order_number() ) ); ?></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 additional 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 );
I've also used the following code in my functions.php file to remove the Subtotal and just below that, the Payment Method. But I still need help removing the other items.
add_filter( 'woocommerce_get_order_item_totals', 'adjust_woocommerce_get_order_item_totals' );
function adjust_woocommerce_get_order_item_totals( $totals ) {
unset($totals['cart_subtotal'] );
unset( $totals['payment_method'] );
return $totals;
}
you can custom the content using woocommerce_email_before_order_table hook
add_action( 'woocommerce_email_before_order_table', 'custom_process_table', 10, 4 );
function custom_process_table( $order, $sent_to_admin, $plain_text, $email ) {
// Your Custom Table goes here
}
you can also override the email template.
https://github.com/woocommerce/woocommerce/blob/master/templates/emails/email-order-details.php
I've been struggling for more than 4 days to customize my small WooCommerce shop email template by wanting to add the following requisites - order number, order date and hour when the order was mode.
This is the email template:
<?php
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 %s,', 'woocommerce' ), esc_html( $order->get_formatted_billing_full_name() ) ); ?></p>
<p><?php esc_html_e( 'Your order №X from date X hour X was processed. You can track the delivery progress by clicking on the shipping number:', 'woocommerce' ); ?></p>
<blockquote><?php echo wpautop( wptexturize( make_clickable( $customer_note ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></blockquote>
<?php
/**
* Show user-defined additional 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 );
You may get values for your needs by following functions
// Get Order ID/Number
$order->get_id();
For Order Dates here are the multiple function with different dates you may use them
// Get Order Dates
$order->get_date_created(); //Order Created Date
$order->get_date_modified(); //Order Modified Date
$order->get_date_completed();//Order Completed Date
$order->get_date_paid(); //Order Paid Date
I hope this helps you
I am trying to create a review reminder email using the Customer invoice / Order details email. We don't use this email so I thought it would be good to change the code to make it a review reminder email and then we can trigger it manually.
I have changed a bit of code, so it now looks like this:
<?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.5.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 %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<p><?php printf( esc_html__("the more you share, the more you help other customers. We would love to know your thoughts on your most recent purchase and we'd appreciate it if you could take a moment to write a quick review.", 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></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
*/
$text_align = is_rtl() ? 'right' : 'left';
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
$after = '</a>';
} else {
$before = '';
$after = '';
}
/* translators: %s: Order ID. */
?>
</h2>
<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="0" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
<tbody>
<?php
echo wc_get_email_order_items( $order, array( // WPCS: XSS ok.
'show_sku' => $sent_to_admin,
'show_image' => true,
'image_size' => array( 100, 100 ),
'plain_text' => $plain_text,
'sent_to_admin' => $sent_to_admin,
) );
?>
</tbody>
</table>
</div>
<p>
<?php esc_html_e( 'Thanks for shopping with us.', 'woocommerce' ); ?>
</p>
<?php
/*
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
I need to add 3 things though:
A static image, below the header, pointing to an image in the media library.
A URL link to the particular product purchased.
This query gives me the product name (and image), quantity and price. I want to get rid of quantity and price and just have the name and image.
I don't want to mess with the main email template code though, so I want to be able to do these things all within this one php file.
Can someone please advise on any of these three items? Thanks!
Copy the email-order-items.php form plugins/woocommerce/templates/emails/ to your wp-content/themefolder/woocommerce/emails/email-order-item.php by doing this you can edit the layout of your email without touching the core functions of woocommerce. The details are already there including the image and the title.
I am trying to find a way to add the Authorize.net ID (not the woocommerce customer ID) to the admin order template. The Authorize.net ID shows on the order screen:
I want that ID # to go in the email. Here is the e-mail template:
<?php
/**
* Admin new order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/admin-new-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/
* #author WooThemes
* #package WooCommerce/Templates/Emails/HTML
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* #hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></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, $transaction_ID );
/**
* #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 );
/**
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
Any ideas? I appreciate any guidance I can get.
This code will display the transaction ID (when it exists) in Woocommerce admin email notifications:
// Display the payment gateway transwaction ID on email notifications
add_action('woocommerce_email_order_details', 'before_email_order_details_transaction_id', 5, 4 );
function before_email_order_details_transaction_id( $order, $sent_to_admin, $plain_text, $email ) {
if( $order->get_transaction_id() && $sent_to_admin )
echo '<p><strong>' . __("Transaction id") . ': </strong>' . $order->get_transaction_id() . '<p>';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
In my WooCommerce web shop, I am using WooCommerce Subscriptions plugin.
I am trying to remove the hyperlink from a woocommerce email template:
I don't see how I can do this from the template below:
<?php
/**
* Customer processing order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-processing-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/
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* #hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<p><?php _e( "Your order has been received and is now being processed. Your order details are shown below for your reference:", 'woocommerce' ); ?></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 );
/**
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
There are no href in the code below, in order to remove said link.
How can I remove this hyperlink?
Thanks
You need to copy the template located in the your subscription plugin:
woocommerce-subscriptions/templates/email/subscriptions-info.php
to your active chlid theme folder (or active theme folder):
your-theme/woocommerce/email/subscriptions-info.php
To understand WooCommerce templates:
Template Structure + Overriding Templates via a Theme
Once done you can change the code in this template at line 27 from here:
<td class="td" scope="row" style="text-align:left;"><?php echo sprintf( esc_html_x( '#%s', 'subscription number in email table. (eg: #106)', 'woocommerce-subscriptions' ), esc_html( $subscription->get_order_number() ) ); ?></td>
Replacing by this:
<td class="td" scope="row" style="text-align:left;"><?php echo sprintf( esc_html_x( '#%s', 'subscription number in email table. (eg: #106)', 'woocommerce-subscriptions' ), esc_html( $subscription->get_order_number() ) ); ?></td>
This is tested and works on WooCommerce 3+