Woocommerce在结帐页面上获取购物车中特定商品的数量


Woocommerce get quantity of specific items in cart on checkout page

我正在尝试在结帐屏幕中显示以 2 件事为条件的自定义字段。

    如果产品 #
  1. 1769 和/或产品 #1770 在客户的购物车中。
  2. 当前购物车中 #1769 和/或 #1770 的数量将决定要显示的自定义字段的数量。

现在我上面有#1

处理以下内容:
/**
* Check to see what is in the cart
*
* @param $product_id
*
* @return bool
*/
function conditional_product_in_cart( $product_id ) {
    //Check to see if user has product in cart
    global $woocommerce;
    $check_in_cart = false;
    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
        $_product = $values['data'];
        if ( $_product->id === $product_id ) {
            $check_in_cart = true;
        }       
    }
    return $check_in_cart;
}
function checkout_register_names( $checkout ) {
$check_in_cart = conditional_product_in_cart(1769); 
    // Product id 1769 is in cart so show custom fields
    if ($check_in_cart === true ) {
    // Display custom fields for 1769...
    woocommerce_form_field( 'golf_field_one', array(
    'type'          => 'text',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Golfer #1'),
    'placeholder'       => __('Name'),
    ), $checkout->get_value( 'golf_field_one' ));
    woocommerce_form_field( 'golf_field_two', array(
    'type'          => 'text',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Golfer #2'),
    'placeholder'       => __('Name'),
    ), $checkout->get_value( 'golf_field_two' ));
    //etc...
    }
$check_in_cart = conditional_product_in_cart(1770); 
    // Product id 1770 is in cart so show custom fields
    if ($check_in_cart === true ) {
    // Display custom fields for 1770...
    woocommerce_form_field( 'dinner_field_one', array(
    'type'          => 'text',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Dinner Name #1'),
    'placeholder'       => __('Name'),
    ), $checkout->get_value( 'dinner_field_one' ));
    woocommerce_form_field( 'dinner_field_two', array(
    'type'          => 'text',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Dinner Name #2'),
    'placeholder'       => __('Name'),
    ), $checkout->get_value( 'dinner_field_two' ));
    //etc...
    }
}

仅当该产品在客户购物车中时,上面的代码才会有条件地显示我在每个产品下设置的所有 woocommerce_form_field()。

现在,我需要做的是根据购物车中每个产品 #1769 或 #1770 的数量显示一定数量的 woocommerce_form_field()。

因此,如果产品 #1769 有两 (2) 个,则应显示两个字段。如果产品 #1769 有两 (2) 个,产品 #1770 有一 (1) 个,则总共应显示三个字段(两个用于产品 #1769,一个用于产品 #1770)。

在任何给定客户的购物车中,每种产品最多只会添加四个,因此将每个表单字段包装在 if() 中并没有什么大不了的,该字段检查以下内容:

if([quantity of product 1769] >= 1) {
    show first woocommerce_form_field()
}
if([quantity of product 1769 >= 2) {
    show second woocommerce_form_field()
} //etc... 
// Repeat for product 1770...

我尝试在第一个function conditional_product_in_cart foreach()中添加$qty_in_cart = $values['quantity'];,但这似乎不想给我任何东西。当我检查if (isset($qty_in_cart))时,它没有设置。

我觉得我很接近,但就是无法弄清楚我错过了什么。任何帮助将不胜感激。

我正在执行相同的任务。我在WooTickets和WooCommerce上使用的这段代码片段可能会帮助你:

    if (    
        in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && 
        in_array( 'wootickets/wootickets.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )
    ) {
    /**
     * Add the field to the checkout
     **/
    add_action('woocommerce_after_order_notes', 'wt_attendee_details');
    function wt_attendee_details( $checkout ) {
        $attendee_count = wt_count_attendees();
        if($attendee_count > 0) {
            echo "</div></div>"; //close the Billing Address section to create new group of fields
            echo "<div id='attendee_details'><div>"; //automatically be closed from 2 Billing Address's div - </div></div>
            echo '<h3>'.__('All Event Attendees and/or clients who are ordering DVDs, please add your name and email again.').'</h3>';
            for($n = 1; $n <= $attendee_count; $n++ ) {
                woocommerce_form_field( 'attendee_name_'.$n, array(
                    'type'          => 'text',
                    'class'         => array('form-row form-row-first'),
                    'label'         => __('Name'),
                    'placeholder'   => __('name'),
                    'required'      => true,
                ), $checkout->get_value( 'attendee_name_'.$n ));
                woocommerce_form_field( 'attendee_email_'.$n, array(
                    'type'          => 'text',
                    'class'         => array('form-row validate-email'),
                    'label'         => __('Email'),
                    'placeholder'       => __('email'),
                    'required'      => true,
                ), $checkout->get_value( 'attendee_email_'.$n ));
                woocommerce_form_field( 'attendee_phone_'.$n, array(
                    'type'          => 'text',
                    'class'         => array('form-row form-row-last'),
                    'label'         => __('Phone'),
                    'placeholder'   => __(''),
                ), $checkout->get_value( 'attendee_phone_'.$n ));
            }
            echo "<style type='text/css'>
                        #attendee_details .form-row {
                            float: left;
                            margin-right: 2%;
                            width: 31%;
                        }
                        #attendee_details .form-row-last {
                            margin-right: 0;
                        }
                    </style>";
        }
        //echo "Attendees: " . $attendee_count;
    }
    /**
     * Process the checkout
     **/
    add_action('woocommerce_checkout_process', 'wt_attendee_fields_process');
    function wt_attendee_fields_process() {
        global $woocommerce;
        $attendee_count = wt_count_attendees();
        for($n = 1; $n <= $attendee_count; $n++ ) {
            if (!$_POST['attendee_email_'.$n] || !$_POST['attendee_name_'.$n])
                $error = true;
                break;
        }
        if($error) {
            $woocommerce->add_error( __('Please complete the attendee details.') );
        }
    }
    /**
     * Update the order meta with field value
     **/
    add_action('woocommerce_checkout_update_order_meta', 'wt_attendee_update_order_meta');
    function wt_attendee_update_order_meta( $order_id ) {
        $attendee_count = wt_count_attendees();
        for($n = 1; $n <= $attendee_count; $n++ ) {
            if ($_POST['attendee_name_'.$n]) update_post_meta( $order_id, $n.' Attendee Name', esc_attr($_POST['attendee_name_'.$n]));
            if ($_POST['attendee_email_'.$n]) update_post_meta( $order_id, $n.' Attendee Email', esc_attr($_POST['attendee_email_'.$n]));
            if ($_POST['attendee_phone_'.$n]) update_post_meta( $order_id, $n.' Attendee Phone', esc_attr($_POST['attendee_phone_'.$n]));
        }
    }
    function wt_count_attendees() {
        global $woocommerce;
        $attendee_count = 0;
        if (sizeof($woocommerce->cart->get_cart())>0) :
            foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
                $_product = $values['data'];
                if ($_product->exists() && $values['quantity']>0) :
                    if (get_post_meta($_product->id, '_tribe_wooticket_for_event') > 0)
                        $attendee_count += $values['quantity'];
                endif;
            endforeach;
        endif;
        return $attendee_count;
    }
}
?>
我知道

这是一个老问题,但我想发布一个新答案,该答案自 8/2015 起使用"活动日历 PRO"v3.11 和"活动日历:WooCommerce 门票"v3.11 插件。

此代码基于 user1664798 的答案,修改为执行以下操作:

  • 更改了使用新插件版本调用错误的方式
  • 显示每个产品的每张门票的与会者字段(因此,如果用户为活动"A"购买 2 张门票,为活动"B"购买 3 张门票,他们将看到 5 个字段 - 前 2 个字段将标有事件"A",最后 3 个字段将标有事件"B")
  • 将与会者添加到WooCommerce电子邮件
  • 将与会者添加到结帐确认页面
  • 将与会者添加到"活动日历:WooCommerce 门票"插件电子邮件

添加到函数.php文件:

if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && in_array( 'wootickets/wootickets.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
    /**
     * Add the field to the checkout
     **/
    add_action('woocommerce_after_order_notes', 'wt_attendee_details');
    function wt_attendee_details( $checkout ) {
        $attendee_count = wt_count_attendees();
        foreach($attendee_count as $event_name => $event_info) {
            $event_slug = $event_info['slug'];
            $attendee_quantity = $event_info['quantity'];
            echo '<hr><h3>'.$event_name.__(' Attendee Information').'</h3>';
            for($n = 1; $n <= $attendee_quantity; $n++ ) {
                woocommerce_form_field( $event_slug.'_attendee_name_'.$n, array(
                    'type'          => 'text',
                    'class'         => array(''),
                    'label'         => __("Attendee #$n Name"),
                    'placeholder'   => __(''),
                    'required'      => true,
                ), $checkout->get_value( $event_slug.'_attendee_name_'.$n ));
                woocommerce_form_field( $event_slug.'_attendee_email_'.$n, array(
                    'type'          => 'text',
                    'class'         => array('form-row-first'),
                    'label'         => __("Attendee #$n Email"),
                    'placeholder'       => __(''),
                ), $checkout->get_value( $event_slug.'_attendee_email_'.$n ));
                woocommerce_form_field( $event_slug.'_attendee_phone_'.$n, array(
                    'type'          => 'text',
                    'class'         => array('form-row-last'),
                    'label'         => __("Attendee #$n Phone"),
                    'placeholder'   => __(''),
                ), $checkout->get_value( $event_slug.'_attendee_phone_'.$n ));
            }
        }
    }
    /**
     * Process the checkout
     **/
    add_action('woocommerce_checkout_process', 'wt_attendee_fields_process');
    function wt_attendee_fields_process() {
        global $woocommerce;
        $attendee_count = wt_count_attendees();
        foreach($attendee_count as $event_name => $event_info) {
            $event_slug = $event_info['slug'];
            $attendee_quantity = $event_info['quantity'];
            for ($n = 1; $n <= $attendee_quantity; $n++) {
                if (!$_POST[$event_slug.'_attendee_name_' . $n])
                    $error = true;
                break;
            }
        }
        if($error) {
            wc_add_notice( __( 'Please complete the attendee details.', 'woocommerce' ), 'error' );
        }
    }
    /**
     * Update the order meta with field value
     **/
    add_action('woocommerce_checkout_update_order_meta', 'wt_attendee_update_order_meta');
    function wt_attendee_update_order_meta( $order_id ) {
        $attendee_count = wt_count_attendees();
        foreach($attendee_count as $event_name => $event_info) {
            $event_slug = $event_info['slug'];
            $attendee_quantity = $event_info['quantity'];
            for ($n = 1; $n <= $attendee_quantity; $n++) {
                if ($_POST[$event_slug.'_attendee_name_' . $n]) update_post_meta($order_id, "$event_name Attendee #$n Name", esc_attr($_POST[$event_slug.'_attendee_name_' . $n]));
                if ($_POST[$event_slug.'_attendee_email_' . $n]) update_post_meta($order_id, "$event_name Attendee #$n Email", esc_attr($_POST[$event_slug.'_attendee_email_' . $n]));
                if ($_POST[$event_slug.'_attendee_phone_' . $n]) update_post_meta($order_id, "$event_name Attendee #$n Phone", esc_attr($_POST[$event_slug.'_attendee_phone_' . $n]));
            }
        }
    }
    function wt_count_attendees() {
        global $woocommerce;
        $attendee_count = array();
        if (sizeof($woocommerce->cart->get_cart())>0) :
            foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
                $_product = $values['data'];
                if ($_product->exists() && $values['quantity']>0) :
                    if (get_post_meta($_product->id, '_tribe_wooticket_for_event') > 0)
                        $attendee_count[$_product->post->post_title] = array('slug' => $_product->post->post_name, 'quantity' => $values['quantity']);
                endif;
            endforeach;
        endif;
        return $attendee_count;
    }
    /**
     * Add attendees to email
     */
    add_action('woocommerce_email_order_meta', 'wt_email_order_meta');
    function wt_email_order_meta($order) {
        $orderMeta = get_post_meta($order->id);
        $hasCustom = false;
        array_walk($orderMeta, function($value, $key) use(&$hasCustom) { if($key[0] != "_") $hasCustom = true; });
        if($hasCustom) {
            echo '<h2 style="color: #557da1; display: block; font-family: ''Helvetica Neue'', Helvetica, Roboto, Arial, sans-serif; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;">'.__( 'Attendee Details', 'woocommerce' ).'</h2>';
            foreach ($orderMeta as $key => $value) {
                if ($key[0] == "_" || !substr_count($key, "Attendee #")) continue; // skip internal meta
                echo '<p style="margin: 0 0 16px;"><strong>' . esc_attr($key) . ':</strong> ' . esc_attr($value[0]) . '</p>';
            }
        }
    }
    /**
     * Add attendees to order confirmation page
     */
    add_action('woocommerce_order_details_after_order_table', 'wt_order_details_after_order_table');
    function wt_order_details_after_order_table($order) {
        $orderMeta = get_post_meta($order->id);
        $hasCustom = false;
        array_walk($orderMeta, function($value, $key) use(&$hasCustom) { if($key[0] != "_") $hasCustom = true; });
        if($hasCustom) {
            echo "<header><h2>".__( 'Attendee Details', 'woocommerce' )."</h2></header>";
            echo '<table class="shop_table order_details table table-simple-body-headers"><tbody>';
            foreach ($orderMeta as $key => $value) {
                if ($key[0] == "_" || !substr_count($key, "Attendee #")) continue; // skip internal meta
                echo '<tr>';
                echo '  <td class="product-name"><strong>'.esc_attr($key).'</strong></td>';
                echo '  <td>'.esc_attr($value[0]).'</td>';
                echo '</tr>';
            }
            echo '</tbody></table>';
        }
    }
    /**
     * Add attendees to tickets page
     */
    add_action('tribe_tickets_ticket_email_bottom', 'wt_tribe_tickets_ticket_email_bottom');
    function wt_tribe_tickets_ticket_email_bottom($tickets) {
        $ticket = $tickets[0];
        $orderMeta = get_post_meta($ticket['order_id']);
        $hasCustom = false;
        array_walk($orderMeta, function($value, $key) use(&$hasCustom) { if($key[0] != "_") $hasCustom = true; });
        if($hasCustom) {
            echo '<table class="inner-wrapper" border="0" cellpadding="0" cellspacing="0" width="620" bgcolor="#f7f7f7" style="margin:0 auto !important; width:620px; padding:0;">';
            echo '  <tr>';
            echo '      <td valign="top" class="ticket-content" align="left" width="580" border="0" cellpadding="20" cellspacing="0" style="padding:20px; background:#f7f7f7;">';
            echo '          <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">';
            echo '              <tr>';
            echo '                  <td valign="top" align="center" width="100%" style="padding: 0 !important; margin:0 !important;">';
            echo '                      <h2 style="color:#0a0a0e; margin:0 0 10px 0 !important; font-family: ''Helvetica Neue'', Helvetica, sans-serif; font-style:normal; font-weight:700; font-size:28px; letter-spacing:normal; text-align:left;line-height: 100%;">';
            echo '                          <span style="color:#0a0a0e !important">Attendee Information</span>';
            echo '                      </h2>';
            echo '                  </td>';
            echo '              </tr>';
            echo '          </table>';
            echo '          <table class="whiteSpace" border="0" cellpadding="0" cellspacing="0" width="100%">';
            echo '              <tr>';
            echo '                  <td valign="top" align="left" width="100%" height="30" style="height:30px; background:#f7f7f7; padding: 0 !important; margin:0 !important;">';
            echo '                      <div style="margin:0; height:30px;"></div>';
            echo '                  </td>';
            echo '              </tr>';
            echo '          </table>';
            echo '          <table class="ticket-details" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">';
            foreach ($orderMeta as $key => $value) {
                if ($key[0] == "_" || !substr_count($key, "Attendee #")) continue; // skip internal meta
                echo '              <tr>';
                echo '                  <td class="ticket-details" valign="top" align="left" style="padding: 0; margin:0 !important;">';
                echo '                      <h6 style="color:#909090 !important; margin:0 0 10px 0; font-family: ''Helvetica Neue'', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;">'.esc_attr($key).'</h6>';
                echo '                  </td>';
                echo '                  <td class="ticket-details" valign="top" align="left" width="10" style="padding: 0; width:10px; margin:0 !important;">';
                echo '                      &nbsp;';
                echo '                  </td>';
                echo '                  <td class="ticket-details" valign="top" align="left" style="padding: 0; margin:0 !important;">';
                echo '                      <span style="color:#0a0a0e !important; font-family: ''Helvetica Neue'', Helvetica, sans-serif; font-size:15px;">'.esc_attr($value[0]).'</span>';
                echo '                  </td>';
                echo '              </tr>';
            }
            echo '          </table>';
            echo '      </td>';
            echo '  </tr>';
            echo '</table>';
        }
    }
}

在你的theme文件夹中创建一个新的文件夹路径和文件:MYTHEME/tribe-events/tickets/email.php(复制自wp-content/plugins/the-events-calendar/src/views/tickets/email.php):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title><?php esc_html_e( 'Your tickets', 'tribe-events-calendar' ); ?></title>
    <meta name="viewport" content="width=device-width" />
    <style type="text/css">
        h1, h2, h3, h4, h5, h6 {
            color : #0a0a0e;
        }
        a, img {
            border  : 0;
            outline : 0;
        }
        #outlook a {
            padding : 0;
        }
        .ReadMsgBody, .ExternalClass {
            width : 100%
        }
        .yshortcuts, a .yshortcuts, a .yshortcuts:hover, a .yshortcuts:active, a .yshortcuts:focus {
            background-color : transparent !important;
            border           : none !important;
            color            : inherit !important;
        }
        body {
            background  : #ffffff;
            min-height  : 1000px;
            font-family : sans-serif;
            font-size   : 14px;
        }
        .appleLinks a {
            color           : #006caa;
            text-decoration : underline;
        }
        @media only screen and (max-width: 480px) {
            body, table, td, p, a, li, blockquote {
                -webkit-text-size-adjust : none !important;
            }
            body {
                width     : 100% !important;
                min-width : 100% !important;
            }
            body[yahoo] h2 {
                line-height : 120% !important;
                font-size   : 28px !important;
                margin      : 15px 0 10px 0 !important;
            }
            table.content,
            table.wrapper,
            table.inner-wrapper {
                width : 100% !important;
            }
            table.ticket-content {
                width   : 90% !important;
                padding : 20px 0 !important;
            }
            table.ticket-details {
                position       : relative;
                padding-bottom : 100px !important;
            }
            table.ticket-break {
                width : 100% !important;
            }
            td.wrapper {
                width : 100% !important;
            }
            td.ticket-content {
                width : 100% !important;
            }
            td.ticket-image img {
                max-width : 100% !important;
                width     : 100% !important;
                height    : auto !important;
            }
            td.ticket-details {
                width         : 33% !important;
                padding-right : 10px !important;
                border-top    : 1px solid #ddd !important;
            }
            td.ticket-details h6 {
                margin-top : 20px !important;
            }
            td.ticket-details.new-row {
                width      : 50% !important;
                height     : 80px !important;
                border-top : 0 !important;
                position   : absolute !important;
                bottom     : 0 !important;
                display    : block !important;
            }
            td.ticket-details.new-left-row {
                left : 0 !important;
            }
            td.ticket-details.new-right-row {
                right : 0 !important;
            }
            table.ticket-venue {
                position       : relative !important;
                width          : 100% !important;
                padding-bottom : 150px !important;
            }
            td.ticket-venue,
            td.ticket-organizer,
            td.ticket-qr {
                width      : 100% !important;
                border-top : 1px solid #ddd !important;
            }
            td.ticket-venue h6,
            td.ticket-organizer h6 {
                margin-top : 20px !important;
            }
            td.ticket-qr {
                text-align : left !important
            }
            td.ticket-qr img {
                float      : none !important;
                margin-top : 20px !important
            }
            td.ticket-organizer,
            td.ticket-qr {
                position : absolute;
                display  : block;
                left     : 0;
                bottom   : 0;
            }
            td.ticket-organizer {
                bottom : 0px;
                height : 100px !important;
            }
            td.ticket-venue-child {
                width : 50% !important;
            }
            table.venue-details {
                position : relative !important;
                width    : 100% !important;
            }
            a[href^="tel"], a[href^="sms"] {
                text-decoration : none;
                color           : black;
                pointer-events  : none;
                cursor          : default;
            }
            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {
                text-decoration : default;
                color           : #006caa !important;
                pointer-events  : auto;
                cursor          : default;
            }
        }
        @media only screen and (max-width: 320px) {
            td.ticket-venue h6,
            td.ticket-organizer h6,
            td.ticket-details h6 {
                font-size : 12px !important;
            }
        }
        @media print {
            .ticket-break {
                page-break-before : always !important;
            }
        }
        <?php do_action( 'tribe_tickets_ticket_email_styles' );?>
    </style>
</head>
<body yahoo="fix" alink="#006caa" link="#006caa" text="#000000" bgcolor="#ffffff" style="width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0 auto; padding:20px 0 0 0; background:#ffffff; min-height:1000px;">
    <div style="margin:0; padding:0; width:100% !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:14px; line-height:145%; text-align:left;">
        <center>
            <?php do_action( 'tribe_tickets_ticket_email_top' ); ?>
            <?php
            $count = 0;
            $break = '';
            foreach ( $tickets as $ticket ) {
                $count ++;
                if ( $count == 2 ) {
                    $break = 'page-break-before: always !important;';
                }
                $event      = get_post( $ticket['event_id'] );
                $header_id  = Tribe__Events__Tickets__Tickets_Pro::instance()->get_header_image_id( $ticket['event_id'] );
                $header_img = false;
                if ( ! empty( $header_id ) ) {
                    $header_img = wp_get_attachment_image_src( $header_id, 'full' );
                }
                $venue_id = tribe_get_venue_id( $event->ID );
                if ( ! empty( $venue_id ) ) {
                    $venue = get_post( $venue_id );
                }
                $venue_name = $venue_phone = $venue_address = $venue_city = $venue_web = '';
                if ( ! empty( $venue ) ) {
                    $venue_name    = $venue->post_title;
                    $venue_phone   = get_post_meta( $venue_id, '_VenuePhone', true );
                    $venue_address = get_post_meta( $venue_id, '_VenueAddress', true );
                    $venue_city    = get_post_meta( $venue_id, '_VenueCity', true );
                    $venue_web     = get_post_meta( $venue_id, '_VenueURL', true );
                }
            ?>
            <table class="content" align="center" width="620" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff" style="margin:0 auto; padding:0;<?php echo $break; ?>">
                <tr>
                    <td align="center" valign="top" class="wrapper" width="620">
                        <table class="inner-wrapper" border="0" cellpadding="0" cellspacing="0" width="620" bgcolor="#f7f7f7" style="margin:0 auto !important; width:620px; padding:0;">
                            <tr>
                                <td valign="top" class="ticket-content" align="left" width="580" border="0" cellpadding="20" cellspacing="0" style="padding:20px; background:#f7f7f7;">
                                    <?php if ( ! empty( $header_img ) ) {
                                        $header_width = esc_attr( $header_img[1] );
                                        if ( $header_width > 580 ) {
                                            $header_width = 580;
                                        }
                                        ?>
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td class="ticket-image" valign="top" align="left" width="100%" style="padding-bottom:15px !important;">
                                                    <img src="<?php echo esc_attr( $header_img[0] ); ?>" width="<?php echo esc_attr( $header_width ); ?>" alt="<?php echo esc_attr( $event->post_title ); ?>" style="border:0; outline:none; height:auto; max-width:100%; display:block;" />
                                                </td>
                                            </tr>
                                        </table>
                                    <?php } ?>
                                    <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
                                        <tr>
                                            <td valign="top" align="center" width="100%" style="padding: 0 !important; margin:0 !important;">
                                                <h2 style="color:#0a0a0e; margin:0 0 10px 0 !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-style:normal; font-weight:700; font-size:28px; letter-spacing:normal; text-align:left;line-height: 100%;">
                                                    <span style="color:#0a0a0e !important"><?php echo $event->post_title; ?></span>
                                                </h2>
                                                <h4 style="color:#0a0a0e; margin:0 !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-style:normal; font-weight:700; font-size:15px; letter-spacing:normal; text-align:left;line-height: 100%;">
                                                    <span style="color:#0a0a0e !important"><?php echo tribe_get_start_date( $event, true ); ?></span>
                                                </h4>
                                            </td>
                                        </tr>
                                    </table>
                                    <table class="whiteSpace" border="0" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>
                                            <td valign="top" align="left" width="100%" height="30" style="height:30px; background:#f7f7f7; padding: 0 !important; margin:0 !important;">
                                                <div style="margin:0; height:30px;"></div>
                                            </td>
                                        </tr>
                                    </table>
                                    <table class="ticket-details" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
                                        <tr>
                                            <td class="ticket-details" valign="top" align="left" width="100" style="padding: 0; width:100px; margin:0 !important;">
                                                <h6 style="color:#909090 !important; margin:0 0 10px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php esc_html_e( 'Ticket #', 'tribe-events-calendar' ); ?></h6>
                                                <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:15px;"><?php echo $ticket['ticket_id']; ?></span>
                                            </td>
                                            <td class="ticket-details" valign="top" align="left" width="120" style="padding: 0; width:120px; margin:0 !important;">
                                                <h6 style="color:#909090 !important; margin:0 0 10px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php esc_html_e( 'Ticket Type', 'tribe-events-calendar' ); ?></h6>
                                                <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:15px;"><?php echo $ticket['ticket_name']; ?></span>
                                            </td>
                                            <td class="ticket-details" valign="top" align="left" width="120" style="padding: 0 !important; width:120px; margin:0 !important;">
                                                <h6 style="color:#909090 !important; margin:0 0 10px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php esc_html_e( 'Purchaser', 'tribe-events-calendar' ); ?></h6>
                                                <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:15px;"><?php echo $ticket['holder_name']; ?></span>
                                            </td>
                                            <td class="ticket-details new-row new-left-row" valign="top" align="left" width="120" style="padding: 0; width:120px; margin:0 !important;">
                                                <h6 style="color:#909090 !important; margin:0 0 10px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php esc_html_e( 'Security Code', 'tribe-events-calendar' ); ?></h6>
                                                <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:15px;"><?php echo $ticket['security_code']; ?></span>
                                            </td>
                                        </tr>
                                    </table>
                                    <table class="whiteSpace" border="0" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>
                                            <td valign="top" align="left" width="100%" height="30" style="height:30px; background:#f7f7f7; padding: 0 !important; margin:0 !important;">
                                                <div style="margin:0; height:30px;"></div>
                                            </td>
                                        </tr>
                                    </table>
                                    <table class="ticket-venue" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
                                        <tr>
                                            <td class="ticket-venue" valign="top" align="left" width="300" style="padding: 0 !important; width:300px; margin:0 !important;">
                                                <h6 style="color:#909090 !important; margin:0 0 4px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php _e( tribe_get_venue_label_singular(), 'tribe-events-calendar' ); ?></h6>
                                                <table class="venue-details" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
                                                    <tr>
                                                        <td class="ticket-venue-child" valign="top" align="left" width="130" style="padding: 0 10px 0 0 !important; width:130px; margin:0 !important;">
                                                            <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:13px; display:block; margin-bottom:5px;"><?php echo $venue_name; ?></span>
                                                            <a style="color:#006caa !important; display:block; margin:0; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:13px; text-decoration:underline;">
                                                                <?php echo $venue_address; ?><br />
                                                                <?php echo $venue_city; ?>
                                                            </a>
                                                        </td>
                                                        <td class="ticket-venue-child" valign="top" align="left" width="100" style="padding: 0 !important; width:140px; margin:0 !important;">
                                                            <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:13px; display:block; margin-bottom:5px;"><?php echo $venue_phone; ?></span>
                                                            <?php if ( ! empty( $venue_web ) ): ?>
                                                                <a href="<?php echo esc_url( $venue_web ) ?>" style="color:#006caa !important; display:block; margin:0; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:13px; text-decoration:underline;"><?php echo $venue_web; ?></a>
                                                            <?php endif ?>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td class="ticket-organizer" valign="top" align="left" width="140" style="padding: 0 !important; width:140px; margin:0 !important;">
                                                <?php $organizers = tribe_get_organizer_ids( $event->ID ); ?>
                                                <h6 style="color:#909090 !important; margin:0 0 4px 0; font-family: 'Helvetica Neue', Helvetica, sans-serif; text-transform:uppercase; font-size:13px; font-weight:700 !important;"><?php echo tribe_get_organizer_label( count($organizers) < 2 ); ?></h6>
                                                <?php foreach ( $organizers as $organizer_id ) { ?>
                                                    <span style="color:#0a0a0e !important; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:15px;"><?php echo tribe_get_organizer( $organizer_id ); ?></span>
                                                <?php } ?>
                                            </td>
                                            <?php $qr_code_url = apply_filters( 'tribe_tickets_ticket_qr_code', '', $ticket ); ?>
                                            <?php if ( ! empty( $qr_code_url ) ): ?>
                                                <td class="ticket-qr" valign="top" align="right" width="160"
                                                    style="padding: 0 !important; width:160px; margin:0 !important;">
                                                    <img src="<?php echo esc_url( $qr_code_url ); ?>" width="140"
                                                         height="140" alt="QR Code Image"
                                                         style="border:0; outline:none; height:auto; max-width:100%; display:block; float:right"/>
                                                </td>
                                            <?php endif; ?>
                                        </tr>
                                    </table>
                                    <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
                                        <tr>
                                            <td class="ticket-footer" valign="top" align="left" width="100%" style="padding: 0 !important; width:100%; margin:0 !important;">
                                                <a href="<?php echo esc_url( home_url() ); ?>" style="color:#006caa !important; display:block; margin-top:20px; font-family: 'Helvetica Neue', Helvetica, sans-serif; font-size:13px; text-decoration:underline;"><?php echo home_url(); ?></a>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                        <table class="whiteSpace" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td valign="top" align="left" width="100%" height="100" style="height:100px; background:#ffffff; padding: 0 !important; margin:0 !important;">
                                    <div style="margin:0; height:100px;"></div>
                                </td>
                            </tr>
                        </table>
                        <?php
                        }
                        ?>

                        <?php do_action( 'tribe_tickets_ticket_email_bottom', $tickets ); ?>
        </center>
    </div>
</body>
</html>

(注意:唯一真正改变的是tribe_tickets_ticket_email_bottom电话的do_action......传递$tickets数组)

最后,对于所有应用程序来说,这可能不够全面,并且确实使用了静态字段......这是为了在非易失性购物车上快速设置......玩弄它...通过一些试验/错误,这可能会帮助其他用户。

此代码自 2015 年 8 月起有效且完整。