2017-11-08 1 views
2

Ich baue einen Shop mit Wordpress und woocommerce und ich muss die admin-new-order.php-Datei umschreiben, um die Bestellung in einem gedruckt zu bekommen POS-Belegdrucker. Alles, was ich tatsächlich brauche, ist, dass die gesendete E-Mail linksbündig formatiert ist und speziell die Produkt-Extras in verschiedenen Zeilen aufgelistet sind, so dass die gedruckte Bestellung nicht gekürzt wird.Customize WooCommerce admin-new-order.php Vorlage in POS-Drucker gedruckt

Das Bild Bälge zeigt eine einfache Text neue Ordnung E-Mail:

email new order plain text

ich die Extra Variation Plugin mit der Lage sein, Extras zu den Produkten hinzuzufügen, aber ich denke, es ist die Antwort nicht beeinflussen Diese Frage, wie woocommerce email-order-items.php anderen Plugins ermöglicht, zusätzliche Produktinformationen hinzuzufügen

Ich habe versucht, die Klartextvorlage von admin-new-order.php zu verwenden und alles hat gut funktioniert, indem Sie beide admin-new-order.php bearbeiten und email-order-details.php, aber ich ge t steckte mit email-order-items.php, wie ich es nicht zwingen kann, die Extras in verschiedenen Reihen aufzulisten.

Mithilfe der HTML-E-Mail konnte ich natürlich diese Tabelle formatieren, aber das würde alle anderen E-Mail-Vorlagen beeinflussen. Aus diesem Grund habe ich versucht, eine admin-new-order.php HTML-Vorlage zu erstellen, die den Code aller drei beteiligten Templates enthält. Wie unten gezeigt, erhalte ich ein "Ungültiges Argument für foreach()" Fehler und kann die Produkte nicht aufgelistet werden.

new order email HTML

Hier ist, wie ich die admin-new-order.php Vorlage codiert:

<?php 
/** 
* Admin new order email hacked by me 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 



//Output the email header 
    do_action('woocommerce_email_header', $email_heading, $email); ?> 

<p><?php printf(__('You have received an order from %s. The order is as follows:', 'woocommerce'), $order->get_formatted_billing_full_name()); ?></p> 

<?php 

//order details 
$text_align = is_rtl() ? 'right' : 'left'; 

do_action('woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email); ?> 

<?php if (! $sent_to_admin) : ?> 
    <h2><?php printf(__('Order #%s', 'woocommerce'), $order->get_order_number()); ?> (<?php printf('<time datetime="%s">%s</time>', $order->get_date_created()->format('c'), wc_format_datetime($order->get_date_created())); ?>)</h2> 
<?php else : ?> 
    <h2><a class="link" href="<?php echo esc_url(admin_url('post.php?post=' . $order->get_id() . '&action=edit')); ?>"><?php printf(__('Order #%s', 'woocommerce'), $order->get_order_number()); ?></a> (<?php printf('<time datetime="%s">%s</time>', $order->get_date_created()->format('c'), wc_format_datetime($order->get_date_created())); ?>)</h2> 
<?php endif; ?> 

<div style="margin-bottom: 40px;"> 
    <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1"> 
     <thead> 
      <tr> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Product', 'woocommerce'); ?></th> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Quantity', 'woocommerce'); ?></th> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Price', 'woocommerce'); ?></th> 
      </tr> 
     </thead> 
     <tbody> 
      <?php/** echo wc_get_email_order_items($order, array(
       'show_sku'  => $sent_to_admin, 
       'show_image' => false, 
       'image_size' => array(32, 32), 
       'plain_text' => $plain_text, 
       'sent_to_admin' => $sent_to_admin, 
      )); */?> 

      <?php 
      //aqui vai entrar o ciclo que lista em cada linha da tabela cada um dos produtos. ISTO ESTÁ A DAR ERRO E NÃO É MOSTRADO. Experiência radical com este do_action aqui em baixo. Radicalmente inventado :D 

      do_action('woocommerce_email_order_items', $order, $sent_to_admin, $plain_text, $email); 


      foreach ($items as $item_id => $item) : 
       $product = $item->get_product(); 
       if (apply_filters('woocommerce_order_item_visible', true, $item)) { 
        ?> 
        <tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order)); ?>"> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php 


          // Product name 
          echo apply_filters('woocommerce_order_item_name', $item->get_name(), $item, false) . "\n"; 
          echo ' X ' . apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); 
          echo ' = ' . $order->get_formatted_line_subtotal($item) . "\n"; 

          // allow other plugins to add additional product information here 
          do_action('woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text); 

          wc_display_item_meta($item); 

          // allow other plugins to add additional product information here 
          do_action('woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text); 

         ?></td> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 0px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">nada</td> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">nada</td> 
        </tr> 
        <?php 
       } 

       if ($show_purchase_note && is_object($product) && ($purchase_note = $product->get_purchase_note())) : ?> 
        <tr> 
         <td colspan="3" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); ?></td> 
        </tr> 
       <?php endif; ?> 

      <?php endforeach; ?> 
      ?> 
     </tbody> 
     <tfoot> 
      <?php 
       if ($totals = $order->get_order_item_totals()) { 
        $i = 0; 
        foreach ($totals as $total) { 
         $i++; 
         ?><tr> 
          <th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th> 
          <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td> 
         </tr><?php 
        } 
       } 
       if ($order->get_customer_note()) { 
        ?><tr> 
         <th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>;"><?php _e('Note:', 'woocommerce'); ?></th> 
         <td class="td" style="text-align:<?php echo $text_align; ?>;"><?php echo wptexturize($order->get_customer_note()); ?></td> 
        </tr><?php 
       } 
      ?> 
     </tfoot> 
    </table> 
</div> 

<?php do_action('woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email); 

// fim de order details?> 
<?php 
// linhas 40 até ao fim do ficheiro original 
/** 
    * @hooked WC_Emails::order_meta() Shows order meta data. 
    */ 
do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); 

/** 
    * @hooked WC_Emails::customer_details() Shows customer details 
    * @hooked WC_Emails::email_address() Shows email address 
    */ 
do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); 

/** 
    * @hooked WC_Emails::email_footer() Output the email footer 
    */ 
do_action('woocommerce_email_footer', $email); 

Wie kann ich um dieses Problem wenden?

Der Laden geht nächsten Montag online und ich muss es herausfinden. Vielen Dank im Voraus für jede Hilfe.

Antwort

0

Es gab einige Fehler wie eine undefinierte $items in einer foreach-Schleife, die durch $order->get_items() und einige andere Kleinigkeiten ersetzt wurde. Diesmal sollte es funktionieren. Hier

ist die Arbeits- und getesteten Code für Ihre angepasste Vorlage:

<?php 
/** 
* Admin new order email hacked by me 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 



//Output the email header 
    do_action('woocommerce_email_header', $email_heading, $email); ?> 

<p><?php printf(__('You have received an order from %s. The order is as follows:', 'woocommerce'), $order->get_formatted_billing_full_name()); ?></p> 

<?php 

$show_purchase_note = true; // ADDED 

//order details 
$text_align = is_rtl() ? 'right' : 'left'; 

do_action('woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email); ?> 

<?php if (! $sent_to_admin) : ?> 
    <h2><?php printf(__('Order #%s', 'woocommerce'), $order->get_order_number()); ?> (<?php printf('<time datetime="%s">%s</time>', $order->get_date_created()->format('c'), wc_format_datetime($order->get_date_created())); ?>)</h2> 
<?php else : ?> 
    <h2><a class="link" href="<?php echo esc_url(admin_url('post.php?post=' . $order->get_id() . '&action=edit')); ?>"><?php printf(__('Order #%s', 'woocommerce'), $order->get_order_number()); ?></a> (<?php printf('<time datetime="%s">%s</time>', $order->get_date_created()->format('c'), wc_format_datetime($order->get_date_created())); ?>)</h2> 
<?php endif; ?> 

<div style="margin-bottom: 40px;"> 
    <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1"> 
     <thead> 
      <tr> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Product', 'woocommerce'); ?></th> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Quantity', 'woocommerce'); ?></th> 
       <th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e('Price', 'woocommerce'); ?></th> 
      </tr> 
     </thead> 
     <tbody> 

      <?php 
      /* 
       echo wc_get_email_order_items($order, array(
       'show_sku'  => $sent_to_admin, 
       'show_image' => false, 
       'image_size' => array(32, 32), 
       'plain_text' => $plain_text, 
       'sent_to_admin' => $sent_to_admin, 
      )); 
      */ 

      do_action('woocommerce_email_order_items', $order, $sent_to_admin, $plain_text, $email); 


      foreach ($order->get_items() as $item_id => $item) : // CHANGED from "$items" to "$order->get_items()" 
       $product = $item->get_product(); 
       if (apply_filters('woocommerce_order_item_visible', true, $item)) { 
        ?> 
        <tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order)); ?>"> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php 


          // Product name 
          echo apply_filters('woocommerce_order_item_name', $item->get_name(), $item, false) . "\n"; 
          echo ' X ' . apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); 
          echo ' = ' . $order->get_formatted_line_subtotal($item) . "\n"; 

          // allow other plugins to add additional product information here 
          do_action('woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text); 

          wc_display_item_meta($item); 

          // allow other plugins to add additional product information here 
          do_action('woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text); 

         ?></td> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 0px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">nada</td> 
         <td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">nada</td> 
        </tr> 
        <?php 
       } 

       if ($show_purchase_note && is_object($product) && ($purchase_note = $product->get_purchase_note())) : ?> 
        <tr> 
         <td colspan="3" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); ?></td> 
        </tr> 
       <?php // CHANGES Below (removed a closing php tag) 
        endif; 
       endforeach; 
      ?> 
     </tbody> 
     <tfoot> 
      <?php 
       if ($totals = $order->get_order_item_totals()) { 
        $i = 0; 
        foreach ($totals as $total) { 
         $i++; 
         ?><tr> 
          <th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th> 
          <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo (1 === $i) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td> 
         </tr><?php 
        } 
       } 
       if ($order->get_customer_note()) { 
        ?><tr> 
         <th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>;"><?php _e('Note:', 'woocommerce'); ?></th> 
         <td class="td" style="text-align:<?php echo $text_align; ?>;"><?php echo wptexturize($order->get_customer_note()); ?></td> 
        </tr><?php 
       } 
      ?> 
     </tfoot> 
    </table> 
</div> 

<?php do_action('woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email); 

// fim de order details?> 
<?php 
// linhas 40 até ao fim do ficheiro original 
/** 
    * @hooked WC_Emails::order_meta() Shows order meta data. 
    */ 
do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); 

/** 
    * @hooked WC_Emails::customer_details() Shows customer details 
    * @hooked WC_Emails::email_address() Shows email address 
    */ 
do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); 

/** 
    * @hooked WC_Emails::email_footer() Output the email footer 
    */ 
do_action('woocommerce_email_footer', $email);