Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce:将类别说明添加到单个产品页面_Php_Wordpress_Woocommerce_Categories_Product - Fatal编程技术网

Php WooCommerce:将类别说明添加到单个产品页面

Php WooCommerce:将类别说明添加到单个产品页面,php,wordpress,woocommerce,categories,product,Php,Wordpress,Woocommerce,Categories,Product,我尝试将添加到content single product.php模板文件中,但没有显示出来 有没有办法将WooCommerce类别说明添加到单个产品页面?要将类别说明添加到单个产品页面,请使用content single product.php模板文件,此代码完成了以下操作: <?php global $post; $args = array( 'taxonomy' => 'product_cat',); $terms = wp_get_post_ter

我尝试将
添加到
content single product.php
模板文件中,但没有显示出来


有没有办法将WooCommerce类别说明添加到单个产品页面?

要将类别说明添加到单个产品页面,请使用
content single product.php
模板文件,此代码完成了以下操作:

<?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>';
            echo $term->description;
            echo '</div>';
        }
    }

?>   

您可以使用此代码将产品类别说明显示到单个产品页面-

<?php global $post, $product;
$categ = $product->get_categories();
$term = get_term_by ( 'name' , strip_tags($categ), 'product_cat' );
echo $term->description; ?>

请添加此代码的源链接参考,并给出一些用法说明(在哪里以及如何使用)。这可能对社区有帮助。谢谢