The php below, is what is in the email theme file in woocommerce at the moment. Here i figured out how to get the billing name to show in the top of the email sent to the user. Next i need to figure out, how to get specific text from the email table - the one that is called 'woocommerce_email_order_details' below - and into the text in "additional content". I dont want all of the order details, but specific details to show in the email.
Does anyone have a solution?
I have read nearly every article on the web, but have not found a solution, as it is not the entire "order details", but only specific details i want to find and use.
`<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_email_header', $email_heading )
/* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Kære %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php
if ($email_data['additional_content'] !== '') {
echo wp_kses_post( wpautop( wptexturize( $email_data['additional_content'] ) ) );
}
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email);
?>`
Related
I would like to remove the link in the plain text email to the admin of the shop, but keep the other information (total, paymenttype, delivery).
I found the template admin_new_order.php and the line but my research was not successful for the details.
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
How to find the available fields for total, payment type, delivery and link? How to remove the link?
The code you are looking for can be found in the following template file
emails/plain/email-customer-details.php
This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/email-order-details.php.
In the copy you create of the template file you can remove: line 49 - 52
if ( $sent_to_admin ) {
/* translators: %s: Order link. */
echo "\n" . sprintf( esc_html__( 'View order: %s', 'woocommerce' ), esc_url( $order->get_edit_order_url() ) ) . "\n";
}
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 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!
In the WooCommerce checkout field shipping_address_2, I have established a custom discount coupon. What I need is to get this order field value in a specific email notification.
Here is my code attempt:
add_action( 'woocommerce_email_before_order_table', 'add_content_to_specific_email', 20, 4 );
function add_content_to_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
if ( $email->id == 'customer_processing_order' ) {
echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong> get_post_meta( $order_id, '_shipping_address_2', true ) </strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}
}
It doesn't works. What I want to transform this field value into a string between <strong> html tags.
Your help is welcome please.
You were very near to get what you were expecting. The correct was instead:
echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong>' . get_post_meta( $order->ger_id(), '_shipping_address_2', true ) . '</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
But it's better to use WC_Order get_shipping_address_2() method.
Here is your revisited code:
add_action( 'woocommerce_email_before_order_table', 'add_content_to_specific_email', 20, 4 );
function add_content_to_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
// For customer processing and completed orders notifications
if ( in_array($email->id, ['customer_processing_order', 'customer_completed_order']) ) {
if( $coupon_code = $order->get_shipping_address_2() ) {
echo '<h2 class="email-upsell-title">'.__("Get 20% off").'</h2>
<p class="email-upsell-p">';
printf(
__("Thank you for making this purchase! Come back and use the code %s to receive a 20%% discount on your next purchase! %s."),
'"<strong>'.$coupon_code.'</strong>"',
'' . __("Click here to continue shopping") . ''
);
echo '</p>';
}
}
}
Code goes in function.php file of your active child theme (or active theme). It should works.
I tried a lot trying to get an input field under shipping details for all orders to show only for admin. But when I am browsing on the internet for that, I am getting plugins which show input box for both customer and admin.
I found this link which might work. But I need to know what files are to be changed according to this link.
If you think this doesn't work, give me your own suggestions.
I need to update that tutorial for WooCommerce 3.0, but in order to show the data to only admins you just need some conditional logic to test whether the user has the correct capabilities... and WordPress happens to have current_user_can() to do just that. manage_plugins is a capability you can test that typically only admins have, so should serve your purpose.
// display the extra data in the order admin panel
function kia_display_order_data_in_admin( $order ){
if( current_user_can( 'manage_plugins' ) { ?>
<div class="order_data_column">
<h4><?php _e( 'Extra Details', 'woocommerce' ); ?></h4>
<?php // get the order id with backcompatibility
$order_id = defined( 'WC_VERSION' ) && version_compare( WC_VERSION, $version, '>=' ) ? $order->get_id() : $order->id;
echo '<p><strong>' . __( 'Some field' ) . ':</strong>' . get_post_meta( $order_id, '_some_field', true ) . '</p>';
echo '<p><strong>' . __( 'Another field' ) . ':</strong>' . get_post_meta( $order_id, '_another_field', true ) . '</p>'; ?>
</div>
<?php }
}
add_action( 'woocommerce_admin_order_data_after_order_details', 'kia_display_order_data_in_admin' );
This is only one of the functions I had in my tutorial, but you'd do pretty much the same with the others.