Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 733 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the Product tags for the current product only in WooCommerce

#1
How can I display only the product tags for the current single product page and not all the products tags?

I've found questions about most popular tags but not for that.
Reply

#2
You can use the function [wp_get_post_terms()][1] function for WooCommerce 'product_tag' custom taxonomy and a defined **product id** this way:

$output = array();

// get an array of the WP_Term objects for a defined product ID
$terms = wp_get_post_terms( get_the_id(), 'product_tag' );

// Loop through each product tag for the current product
if( count($terms) > 0 ){
foreach($terms as $term){
$term_id = $term->term_id; // Product tag Id
$term_name = $term->name; // Product tag Name
$term_slug = $term->slug; // Product tag slug
$term_link = get_term_link( $term, 'product_tag' ); // Product tag link

// Set the product tag names in an array
$output[] = '<a href="'.$term_link.'">'.$term_name.'</a>';
}
// Set the array in a coma separated string of product tags for example
$output = implode( ', ', $output );

// Display the coma separated string of the product tags
echo $output;
}

Tested and works.

You can replace `get_the_id()` by a dynamic product Id variable too.


[1]:

[To see links please register here]

Reply

#3
You can now use the [`wc_get_product_tag_list()`][1] function to get a list of the product's tags. It supports providing a separator along with before and after elements.

**Example**

<?php
global $product;
?>
<div class="product-tags">
<?php echo wc_get_product_tag_list( $product->get_id(), ', ' ); ?>
</div>


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through