• Resolved cimita

    (@cimita)


    Hi,

    I modified the template of the email_order_items by only adding a new column and it displays correctly in the client email. But in the admin email it does not display, and is like it doesn’t exist. I also added a <th> in email_order_details with the header of the column. That’s it!

    Can you please help? Thank you!

    <?php
    /**
     * Email Order Items
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-items.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see 	    https://docs.woocommerce.com/document/template-structure/
     * @author 		WooThemes
     * @package 	WooCommerce/Templates/Emails
     * @version     2.1.2
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    foreach ( $items as $item_id => $item ) :
    	$_product     = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
    	$item_meta    = new WC_Order_Item_Meta( $item, $_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:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php
    
    				// Show title/image etc
    				if ( $show_image ) {
    					echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
    				}
    
    				// Product name
    				echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
    
    				// SKU
    				if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
    					echo ' (#' . $_product->get_sku() . ')';
    				}
    
    				// allow other plugins to add additional product information here
    				do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
    
    				// Variation
    				if ( ! empty( $item_meta->meta ) ) {
    					echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
    				}
    
    				// File URLs
    				if ( $show_download_links ) {
    					$order->display_item_downloads( $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:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ); ?></td>
    
    			<!--NEW COLUMN-->
    			<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
        		<?php
    			
    			if ( ! $short_description || $_product->is_type('variation')) {
    				
    					$_product = wc_get_product( $item->get_product_id() );
    				
    				echo wp_kses_post( apply_filters( 'woocommerce-product-details__short-description', $_product->get_short_description(), $cart_item, $cart_item_key ) . '&nbsp;' );
    				} 
    				else {
    					
    			echo wp_kses_post( apply_filters( 'woocommerce-product-details__short-description', sprintf('woocommerce-product-details__short-description', esc_url ( $short_description ), $_product->get_short_description()), $cart_item, $cart_item_key ) );
    
    			};
    
        		?>	
    			</td>
    			<!--END NEW COLUMN-->
    
    			<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
    		</tr>
    		<?php
    	}
    
    	if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
    		<tr>
    			<td colspan="3" style="text-align:left; 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; ?>
    
    <?php
    /**
     * Order details table shown in emails.
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see 	    https://docs.woocommerce.com/document/template-structure/
     * @author 		WooThemes
     * @package 	WooCommerce/Templates/Emails
     * @version     2.5.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    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() ); ?></h2>
    <?php else : ?>
    	<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce'), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>
    <?php endif; ?>
    
    <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:left;"><?php _e( 'Product', 'woocommerce' ); ?></th>
    			<th class="td" scope="col" style="text-align:left;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
    						<!--MIO--><th class="td" scope="col" style="text-align:center;"><?php _e( 'UOM', 'woocommerce' ); ?></th><!--END MIO-->
    			<th class="td" scope="col" style="text-align:left;"><?php _e( 'Price', 'woocommerce' ); ?></th>
    		</tr>
    	</thead>
    	<tbody>
    		<?php echo $order->email_order_items_table( array(
    			'show_sku'      => $sent_to_admin,
    			'show_image'    => false,
    			'image_size'    => array( 32, 32 ),
    			'plain_text'    => $plain_text,
    			'sent_to_admin' => $sent_to_admin
    		) ); ?>
    	</tbody>
    	<tfoot>
    		<?php
    			if ( $totals = $order->get_order_item_totals() ) {
    				$i = 0;
    				foreach ( $totals as $total ) {
    					$i++;
    					?><tr>
    						<th class="td" scope="row" colspan="3" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
    						<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
    					</tr><?php
    				}
    			}
    		?>
    	</tfoot>
    </table>
    
    <?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
    
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changes in client email display correctly but in admin not’ is closed to new replies.