WordPress.org

Forums

WooCommerce - excelling eCommerce
Product tags in order confirmation email? (9 posts)

  1. kazie
    Member
    Posted 1 year ago #

    I need to add the product brand (tags) next to the product name in the order confirmation email received by the customer. How would I go about doing that? I have tried editing email-order-items.php, but no luck so far.

    http://wordpress.org/extend/plugins/woocommerce/

  2. IgniteWoo Team
    Member
    Posted 1 year ago #

    Do you know how to pull tags from the database in general? In WooCommerce, it would work the same as in WordPress for getting post tags.

    http://codex.wordpress.org/Function_Reference/wp_get_post_terms

    Something like

    $term_list = wp_get_post_terms( $product_id, 'product_tag', array( "fields" => "names" ) );
    print_r($term_list);

    You have to modify that to include the correct product ID, and some code to print the tag list. But that's a start.

  3. kazie
    Member
    Posted 1 year ago #

    Hm, not sure what to do. I only get "Array ( )" in return.

  4. Alan Cesarini
    Member
    Posted 1 year ago #

    The function wp_get_post_terms returns an array of terms, so to show them all, you need to do this:

    foreach( $term_list as $term ) echo $term . '<br/>'

  5. kazie
    Member
    Posted 1 year ago #

    Could you please post the entire code-snippet?

  6. Alan Cesarini
    Member
    Posted 1 year ago #

    $term_list = wp_get_post_terms( $product_id, 'product_tag', array( "fields" => "names" ) );
    foreach( $term_list as $term ) echo $term . '<br/>';

    The first line will get all tags associated with the product, and the second line will display them all.

  7. kazie
    Member
    Posted 1 year ago #

    This is what my code looks like now, but it's not outputting the product brand.

    <?php
    
    			$term_list = wp_get_post_terms( $product_id, 'product_tag', array( "fields" => "names" ) );
    			foreach( $term_list as $term ) echo $term . '<br/>';
    
    			// Show title/image etc
    			echo 	apply_filters( 'woocommerce_order_product_image', $image, $_product, $show_image);
    
    			// Product name
    			echo 	apply_filters( 'woocommerce_order_product_title', $item['name'], $_product );
    
    			// SKU
    			echo 	($show_sku && $_product->get_sku()) ? ' (#' . $_product->get_sku() . ')' : '';
    
    			// File URLs
    			if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
    
    				$download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item );
    
    				$i = 0;
    
    				foreach ( $download_file_urls as $file_url => $download_file_url ) {
    					echo '<br/><small>';
    
    					if ( count( $download_file_urls ) > 1 ) {
    						echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 );
    					} elseif ( $i == 0 )
    						echo __( 'Download:', 'woocommerce' );
    
    					echo ' <a href="' . $download_file_url . '" target="_blank">' . basename( $file_url ) . '</a></small>';
    
    					$i++;
    				}
    			}
    
    			// Variation
    			echo 	($item_meta->meta) ? '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>' : '';
    
    		?>
  8. Alan Cesarini
    Member
    Posted 1 year ago #

    I see. Try this:

    $term_list = wp_get_post_terms( $_product->id, 'product_tag', array( "fields" => "names" ) );
    			foreach( $term_list as $term ) echo $term . '<br/>';
  9. kazie
    Member
    Posted 1 year ago #

    There we go! Thanks a million.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.