Woocommerce erhält die Menge bestimmter Artikel im Warenkorb auf der Checkout-Seite

Lesezeit: 23 Minuten

Ich versuche, benutzerdefinierte Felder im Checkout-Bildschirm anzuzeigen, die von zwei Dingen abhängig sind.

  1. Wenn sich Produkt Nr. 1769 und/oder Produkt Nr. 1770 im Warenkorb des Kunden befinden.
  2. Die Menge von #1769 und/oder #1770 im aktuellen Einkaufswagen bestimmt die Anzahl der anzuzeigenden benutzerdefinierten Felder.

Im Moment habe ich mich um Nr. 1 oben mit Folgendem gekümmert:

/**
* 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...
    }
}

Der obige Code zeigt bedingt alle woocommerce_form_field() an, die ich unter jedem Produkt festgelegt habe, nur wenn sich dieses Produkt im Warenkorb des Kunden befindet.

Jetzt muss ich eine bestimmte Anzahl von woocommerce_form_field() anzeigen, basierend darauf, wie viele von jedem Produkt Nr. 1769 oder Nr. 1770 sich im Warenkorb befinden.

Wenn es also zwei (2) von Produkt Nr. 1769 gibt, sollten zwei Felder angezeigt werden. Wenn es zwei (2) von Produkt Nr. 1769 und eines (1) von Produkt Nr. 1770 gibt, sollten drei Gesamtfelder angezeigt werden (zwei für Produkt Nr. 1769 und eines für Produkt Nr. 1770).

Es werden höchstens vier von jedem Produkt in den Warenkorb eines bestimmten Kunden hinzugefügt, daher ist es keine große Sache, jedes Formularfeld in ein if() zu verpacken, das so etwas prüft wie:

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

Ich habe versucht hinzuzufügen $qty_in_cart = $values['quantity']; zum foreach() in der ersten function conditional_product_in_cart, aber das scheint mir nichts geben zu wollen. Wenn ich nachschaue if (isset($qty_in_cart))es ist nicht eingestellt.

Ich fühle mich, als wäre ich nah dran, aber ich kann einfach nicht herausfinden, was mir fehlt. Jede Hilfe wäre willkommen.

  • $Werte[‘quantity’] sollte funktionieren

    – Dramasee

    29. Oktober 2014 um 6:00 Uhr

Benutzer-Avatar
Schalk Joubert

Ich bin auf derselben Mission. Dieses Code-Snippet, das ich bei WooTickets und WooCommerce verwende, könnte Ihnen helfen:

    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;

    }
}

?>

  • Kurze Frage zur Funktion wt_count_attendees()…the ‘_tribe_wooticket_for_event’ – ist das ein einzelner Produkt-Slug? Wo kommt das her?

    – ScottD

    22. April 2014 um 18:59 Uhr

  • Dies ist ein Metaschlüssel, der von TheEventsCalendar festgelegt wird. Es verbindet ein Event mit einem Produkt (Ticket). Es speichert den Wert der zugeordneten Ereignis-ID.

    – Rob W

    20. Oktober 2015 um 21:33 Uhr

Ich weiß, dass dies eine alte Frage ist, aber ich wollte eine neue Antwort posten, die ab 8/2015 mit “The Events Calendar PRO” v3.11 und den “The Events Calendar: WooCommerce Tickets” v3.11-Plugins funktioniert.

Dieser Code basiert auf der Antwort von user1664798 und wurde geändert, um Folgendes auszuführen:

  • Geändert, wie Fehler mit neuer Plugin-Version aufgerufen werden
  • Zeigen Sie die Teilnehmerfelder PRO Ticket PRO Produkt an (wenn der Benutzer also 2 Tickets für Veranstaltung „A“ und 3 Tickets für Veranstaltung „B“ kauft, werden ihm 5 Felder angezeigt – die ersten 2 Felder werden mit Veranstaltung „A“ gekennzeichnet und die letzten 3 Felder mit Ereignis “B”)
  • Fügen Sie Teilnehmer zu WooCommerce-E-Mails hinzu
  • Fügen Sie der Checkout-Bestätigungsseite Teilnehmer hinzu
  • Teilnehmer zur Plugin-E-Mail „The Events Calendar: WooCommerce Tickets“ hinzufügen

Fügen Sie zu Ihrer functions.php-Datei hinzu:

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

Erstellen Sie einen neuen Ordnerpfad und eine neue Datei in Ihrem Themenordner: MYTHEME/tribe-events/tickets/email.php (kopiert von 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="https://stackoverflow.com/questions/22824303/<?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>

(Anmerkung: Das einzige, was sich wirklich geändert hat, war die do_action für die tribe_tickets_ticket_email_bottom Anruf … vorbei $tickets Reihe)

Schließlich ist dies möglicherweise nicht umfassend genug für alle Anwendungen und verwendet statische Felder … dies sollte schnell auf einem nichtflüchtigen Einkaufswagen eingerichtet werden … Spielen Sie damit herum … und mit etwas Versuch / Irrtum, Dies wird wahrscheinlich anderen Benutzern helfen.

Dieser Code funktioniert und ist seit 8/2015 vollständig.

  • Ich versuche, ein ähnliches Problem zu lösen, und Ihr Beitrag enthält hilfreiche Informationen. Vielen Dank für das Teilen dieses Codes.

    – Drake

    20. Oktober 2015 um 15:59 Uhr

1283880cookie-checkWoocommerce erhält die Menge bestimmter Artikel im Warenkorb auf der Checkout-Seite

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy