Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    You know how to edit email templates right? Sent you links in the past.

    In the one which outputs products, you’d just use something like: echo $product->post->post_name;

    Thread Starter MagineM

    (@maginem)

    Hi Mike,

    Thanks. Yeah, editing the files is not a problem. It’s the syntax… I’ve tried the above code with no luck unfortunately. Have been trying all sorts of combinations but just can’t seem to get it to work.

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Can you share your file with your attempted $product->post->post_name; change?

    Thread Starter MagineM

    (@maginem)

    Hi Mike,

    Here is the main portion of my code in the email-order-items.php file:

    My code for the slug is commented with //POST NAME

    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() . ') ';
    				}
    
    				// POST NAME
    				echo $product->post->post_name;
    
    				// allow other plugins to add additional product information here
    				do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );
    
    				// 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 );
    
    			?></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>
    			<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>
    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Change $product to $_product

    Thread Starter MagineM

    (@maginem)

    Awesome! Works 100%! Thank you again 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display product slug / post_name in Email’ is closed to new replies.