WordPress主题中的WooCommerce支持不起作用



我是wordpress的初学者,我尝试了所有方法,但我无法使我的主题woocommerce支持。下面是我的页面.php

页.php

<?php
/**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 */
?>
<?php get_header(); ?>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="page">
            <?php if ( have_posts() ) : ?>
            <?php while( have_posts() ) : the_post(); ?>
                <div class="post">
                    <h3 class="<?php post_class(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div>
                    <?php
                        // If comments are open or we have at least one comment, load up the comment template.
                        if ( comments_open() || get_comments_number() ) {
                            comments_template();
                        }
                    ?>
                </div>
            <?php endwhile; ?>
            <?php endif; ?>
        </div>
    </div>
<?php get_footer(); ?>

起初我复制page.php并创建woocommerce.php并上传到服务器,但它失败了,以下是我woocommerce.php

呜呜.php

<?php
/**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 */
?>

<?php get_header(); ?>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="page">
            <?php woocommerce_content(); ?>
        </div>
    </div>
<?php get_footer(); ?>

但是它失败了,在此之后,我从服务器中删除了woocommerce.php并编辑了我的functions.php文件以添加woocommerce支持的代码。下面是我在functions.php文件中添加的代码。

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
  echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><div class="page">';
}
function my_theme_wrapper_end() {
  echo '</div></div>';
}
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

但它也失败了,你可以在这里看到输出

如果您在调试器中看到,您可以看到没有加载 woocommerce css 文件。

请帮我提出你的建议。谢谢。

转到函数.php并将其添加到顶部,

add_theme_support('woocommerce');

最优选在初始化函数中。

最新更新