Osh*_*rib 9 php wordpress woocommerce
我有常规wordpress代码来显示类别描述:
<?php echo category_description( $category_id ); ?>
Run Code Online (Sandbox Code Playgroud)
但是,我如何显示Woocommerce类别描述?@@在评论建议之一后我补充说:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
global $post, $product; $categ = $product->get_categories(); $term = get_term_by ( 'name' , strip_tags($categ), 'product_cat' ); echo $term->description;
} // end while
} // end if
?>
Run Code Online (Sandbox Code Playgroud)
不过,不行.
cod*_*abs 12
$args = array( 'taxonomy' => 'product_cat' );
$terms = get_terms('product_cat', $args);
$count = count($terms);
if ($count > 0) {
foreach ($terms as $term) {
echo $term->description;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑最后的答案:
<?php
global $post;
$args = array( 'taxonomy' => 'product_cat',);
$terms = wp_get_post_terms($post->ID,'product_cat', $args);
$count = count($terms);
if ($count > 0) {
foreach ($terms as $term) {
echo '<div style="direction:rtl;">';
echo $term->description;
echo '</div>';
}
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29828 次 |
| 最近记录: |