Woocommerce评级未显示在新的自定义主题中

vra*_*esh 7 php wordpress woocommerce

我正在研究新的自定义主题.我已经安装了woocommerce插件.我有来自xml文件的导入产品.我曾尝试测试评级功能.它的工作在wordpress默认主题twentytwelve,twentysixteen.等等,但当我切换到我的自定义主题.评论部分没有显示评级.

看看屏幕截图.评论部分只有textarea.

这是我的comments.php代码

<div class="comments">
    <?php if (post_password_required()) : ?>
    <p><?php _e( 'Post is password protected. Enter the password to view any comments.', 'html5blank' ); ?></p>
</div>

    <?php return; endif; ?>

<?php if (have_comments()) : ?>

    <h2><?php comments_number(); ?></h2>

    <ul>
        <?php wp_list_comments('type=comment&callback=html5blankcomments'); // Custom callback in functions.php ?>
    </ul>

<?php elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) : ?>

    <p><?php _e( 'Comments are closed here.', 'html5blank' ); ?></p>

<?php endif; ?>

<?php comment_form(); ?>

</div>
Run Code Online (Sandbox Code Playgroud)

我的截图

Out*_*ess 8

如果您使用自定义主题以使其与WooCommerce兼容,则可能需要声明WooCommerce支持.默认的WordPress主题通常与WooCommerce兼容,它们可以在不添加任何内容的情况下工作.您可以在这里阅读更多内容 - https://docs.woocommerce.com/document/third-party-custom-theme-compatibility/.

第1步:将其添加到主题的'functions.php'中.

function custom_theme_setup() {
    add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );
Run Code Online (Sandbox Code Playgroud)

第2步:如果仍然没有显示评论,请将您的主题'page.php'复制为'woocommerce.php'.删除循环 - <?php if(have_posts()): while(have_posts()): the_post(); ?><?php endwhile; endif; ?>.替换the_content()woocommerce_content().

让我知道这些是否解决了这个问题,或者在你的问题中粘贴新的'woocommerce.php'内容.