WordPress.org

Support

Support » Plugins and Hacks » Product tags in order confirmation email?

Product tags in order confirmation email?

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

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

    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/>'

    Could you please post the entire code-snippet?

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

    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>' : '';
    
    		?>

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

    There we go! Thanks a million.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Product tags in order confirmation email?’ is closed to new replies.