首先,您的主要问题是:
如何从订单(Id)获取预订ID?
由于一个订单可以有很多预订(项目),因此您可以通过使用WordPress
WPDB类和可用方法的非常简单且轻巧的SQL查询来获取针对邮寄上级的预订ID(即订单ID)。
然后,您将能够从该订单的一次预订中获得开始日期,并将其设置为电子邮件通知主题的自定义占位符:
// Custom function to get the booking Ids from an order Id (with an SQL query)function wc_get_booking_ids( $order_id ){ global $wpdb; return $wpdb->get_col( $wpdb->prepare( "SELECt ID FROM {$wpdb->posts} WHERe post_type = 'wc_booking' AND post_parent = %d", $order_id ) );}// For woocommerce versions up to 3.2add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );function filter_email_format_string( $string, $email ) { if( ! is_a($email->object, 'WC_Order') ) return; // Exit $booking_ids = wc_get_booking_ids( $email->object->get_id() ); if( ! empty($booking_ids) ) { // Get the instance of the WC_Booking object from one booking Id $booking = new WC_Booking( reset($booking_ids) ); if( is_a($booking, 'WC_Booking') && method_exists($booking, 'get_start_date') ) { // Additional placeholders array (one by line) $custom_placeholders = array( '{start_date}' => $start_date = $booking->get_start_date(), ); $string = str_replace( array_keys( $custom_placeholders ), array_values( $custom_placeholders ), $string ); } } return $string;}代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。



