1

我想customer-completed-order.php在 WooCommerce Bookings 中自定义模板,并想添加如下一行。

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.

我想May 11, 2020, 7:00 pm in timezone: Asia/Tokyo用实际的预订时间/日期替换。这会自动显示在原始电子邮件中,看起来它依赖于booking-summary-list.php文件,但我似乎不能只选择时间和日期来显示我想要的方式。

我是 PHP 的初学者,所以仍然试图弄清楚这一切是如何组合在一起的。我相信以下两个来源也会有所帮助。

https://www.thathandsomebeardedguy.com/retrieve-booking-meta-data

WooCommerce 预订电子邮件模板

https://docs.woocommerce.com/document/bookings-snippets

我可以编写一个类似以下的函数,然后将其添加到该customer-completed-order.php文件中吗?这目前根本不起作用。我相信$order我传入的可能不需要或不正确。还需要将其放在实际的时间/日期行中,但我暂时保留它以查看整个函数并一起调用。

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

我将包括到目前为止我编辑过的整个文件,这样你就可以更好地了解到目前为止我一起破解的内容。再次,超级初学者,非常感谢任何帮助!

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

任何帮助都会非常有帮助。

4

1 回答 1

0

我能够通过执行以下两个步骤来解决这个问题。如果将来其他人遇到此问题,希望这会有所帮助。

首先,我将以下函数添加到我的 functions.php 文件中。

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;
    }   
}

然后在我的实际文件中,booking-summary-list.php我能够调用该函数。

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

干杯!

于 2020-05-28T07:42:54.040 回答