簡體   English   中英

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

因此,如果有兩(2)個產品#1769,則應顯示兩個字段。 如果有兩(2)個產品#1769和一個(1)產品#1770,則應顯示三個總字段(兩個用於產品#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...

我嘗試添加$qty_in_cart = $values['quantity']; 在第一個function conditional_product_in_cartforeach() ,但似乎不想給我任何東西。 當我檢查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;

    }
}

?>

我知道這是一個老問題,但我想發布一個新的答案,截止到2015年8月使用“The Events Calendar PRO”v3.11和“The Events Calendar:WooCommerce Tickets”v3.11插件。

此代碼基於user1664798的答案,修改后執行以下操作:

  • 更改了新插件版本的錯誤調用方式
  • 顯示與會者字段PER票證PER產品(因此,如果用戶購買2個事件“A”的票證,3個事件“B”票證,他們將看到5個字段 - 前2個字段將標有事件“A”,並且事件“B”的最后3個字段)
  • 將與會者添加到WooCommerce電子郵件中
  • 將與會者添加到結帳確認頁面
  • 將與會者添加到“活動日歷:WooCommerce門票”插件電子郵件中

添加到您的functions.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>';
        }
    }
}

在主題文件夾中創建一個新的文件夾路徑和文件: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>

(注:即真正改變是唯一do_actiontribe_tickets_ticket_email_bottom電話...傳遞$tickets陣列)

最后,這對於所有應用程序來說可能不夠全面,並且確實使用了靜態字段...這是為了在非易失性購物車上快速設置...玩它...並且有一些試驗/錯誤,這可能會有助於其他用戶。

此代碼自2015年8月起正常運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM