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?
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):