Faheem Raza
Faheem Raza

Reputation: 9

How can I show Products tags on same product page in WooCommerce

I'm using WooCommerce plugin.

I want to show "Products tags" for the same product on single product page. I have tried everything and it hasn't worked.

Please, can anyone help me with some solution?

Upvotes: 1

Views: 8768

Answers (2)

LoicTheAztec
LoicTheAztec

Reputation: 254378

1) You can use this code snippet to display product tags on single product page template (content-single-product.php):

global $products;
$product_id = $product->id;
$product_tags = get_the_term_list($product_id, 'product_tag', '', ',' );
echo '<p class="single-product-tags">'. __( "Tags: ", "your_theme_slug" ) . $product_tags . '<p>';

WC templates reference: Overriding Templates via a Theme

2) You can also use woocommerce_single_product_summary hook with a priority up to 70, to display your product related tags. You will need to paste this code snippet in the function.php file of your active child theme or theme:

function display_single_product_tags_after_summary() { 
    global $products;
    $product_id = $product->id;
    $product_tags = get_the_term_list($product_id, 'product_tag', '', ',' );
    echo '<p class="single-product-tags">'. __( "Tags: ", "your_theme_slug" ) . $product_tags . '<p>';
};
add_action( 'woocommerce_single_product_summary', 'display_single_product_tags_after_summary', 100, 0 );

For info > The woocommerce_single_product_summary hook display order (priorities):

/**
 * woocommerce_single_product_summary hook.
 *
 * @hooked woocommerce_template_single_title - 5
 * @hooked woocommerce_template_single_rating - 10
 * @hooked woocommerce_template_single_price - 10
 * @hooked woocommerce_template_single_excerpt - 20
 * @hooked woocommerce_template_single_add_to_cart - 30
 * @hooked woocommerce_template_single_meta - 40
 * @hooked woocommerce_template_single_sharing - 50
 */

References (and thanks):

Woocommerce, get current product id or title within sidebar

Get WooCommerce products tags for array of products

Upvotes: 3

Manthan Dave
Manthan Dave

Reputation: 2147

Well its depends on your theme but standard way is :

global $product; // gets the Product object (correspoding to the single page)
$product->get_tags( $product ); // returns an array with product tags

Upvotes: 0

Related Questions