I'm using Woocommerce as a catalog for a website.
I would like to show the category description in every product page.
It's that possibile by editing my theme or maybe with a plugin? I can't find anything.
Thanks!
I'm using Woocommerce as a catalog for a website.
I would like to show the category description in every product page.
It's that possibile by editing my theme or maybe with a plugin? I can't find anything.
Thanks!
Share Improve this question asked Mar 7, 2019 at 15:48 BeatriceBeatrice 11 silver badge1 bronze badge 1- Are you want to show the category description in every product page means on product detail page??? and also share a screenshot of that so I can help you. – Tanmay Patel Commented Mar 8, 2019 at 4:28
2 Answers
Reset to default 0This will display the categories.
<?php
$args = array('taxonomy' => 'product_cat');
$terms = get_terms('product_cat', $args);
$count = count($terms);
if ($count > 0) {
foreach ($terms as $term) {
echo '<p>' . $term->description . '</p>';
}
}
?>
Where you put it depends on your theme. In your theme or child theme you need to create these folders woocommerce > single-product > meta.php
.
You will most likely need to edit the above code for your needs but it should give you an idea.
You can simply add this to your functions.php file of your child theme.
function display_product_category_descriptions(){
global $product;
$terms = get_the_terms( $product->get_id(), 'product_cat');
foreach ($terms as $term) {
echo '<p>' . $term->description . '</p>';
}
}
add_action( 'woocommerce_single_product_summary', 'display_product_category_descriptions', 45);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744865860a4597973.html
评论列表(0条)