• I’ve managed to register new taxonomies: brand and label attached to product. Everything works fine and the last thing to do is to add these to be clickable on front end of single product alongside product categories and product tags. After doing some search I just need to adjust the meta.php in wp-content/plugins/woocommerce/templates/single-product. Question is, how to achieve that?

    meta.php of woocommerce 4.2:

    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    global $post, $product;
    
    $cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
    
    ?>
    <div class="product_meta">
    
    	<?php do_action( 'woocommerce_product_meta_start' ); ?>
    
    	<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
    
    		<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
    
    	<?php endif; ?>
    
    	<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
    
    	<?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
    
    	<?php do_action( 'woocommerce_product_meta_end' ); ?>
    
    </div>

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello there,

    Could you please try to add the following code inside the <div class=”product_meta”> ?

    $terms = get_terms( 'NEW_TAXONOMY_SLUG' ); 
    
    echo '<div class="my-custom-taxonomy">';
    
    foreach ( $terms as $term ) {
    
        // The $term is an object, so we don't need to specify the $taxonomy.
        $term_link = get_term_link( $term );
    
        // If there was an error, continue to the next term.
        if ( is_wp_error( $term_link ) ) {
            continue;
        }
    
        // We successfully got a link. Print it out.
        echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>, ';
    }
    
    echo '</div>';

    You should need to replace NEW_TAXONOMY_SLUG to your taxonomy slug.

    I hope this reply helps.

    Thread Starter tenyom

    (@tenyom)

    No changes at all. Here is the link to a screenshot of the single product front end after inserting the code.
    Question Update: Adding the taxonomy name before the taxonomy slug would be preferable.

    Hello there,

    Thank you for reporting. Could you please try to use the following?

    $terms = get_the_terms( $post->ID, 'NEW_TAXONOMY_SLUG' );
    
    echo '<div class="my-custom-taxonomy">';
    
    foreach ( $terms as $term ) {
    
        // The $term is an object, so we don't need to specify the $taxonomy.
        $term_link = get_term_link( $term->term_id );
    
        // If there was an error, continue to the next term.
        if ( is_wp_error( $term_link ) ) {
            continue;
        }
    
        // We successfully got a link. Print it out.
        echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>, ';
    }
    
    echo '</div>';

    Don’t forget to replace the NEW_TAXONOMY_SLUG with your own.

    Let me know if it changes anything.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Taxonomy of Product on Single Product Front End’ is closed to new replies.