首页 文章

Woocommerce产品和类别页面具有与其他WC页面不同的模板

提问于
浏览
0

我有一个使用WooCommerce销售商品的网站 . 这是我的演示网站:

http://demo.bergdahl.com/

您可以在此处查看电子商务页面及其布局:

Layout 1 (left and right sidebars): 产品列表:http://demo.bergdahl.com/shop/分类页面:http://demo.bergdahl.com/product-category/catridges/

Layout 2 (right sidebar only): 单品页:http://demo.bergdahl.com/product/6-oz-catridge/

我已经得到它以便大多数WooCommerce页面使用布局1,除了具有布局2的单个产品页面 . 布局2被设置为主题中的默认布局并且适用于该站点的其他170个页面 . 我不想更改默认布局,我只想找出可用于设置单个产品页面布局的页面 .

基本上,我想让所有WC页面都使用布局1 .

我的问题是,WooCommerce如何选择将哪种布局分配给哪种类型的页面?

似乎从博客页面布局中提取了产品列表和类别页面 . 购物车,结帐和我的帐户从他们的实际页面中拉出 . I am not sure how to set the layout in the single product page.

附: - 此网站使用较旧的主题,没有WC支持 . 我不知道这可能是问题,但我只能通过使用此处列出的woocommerce_content()方法来调整主题:https://docs.woocommerce.com/document/third-party-custom-theme-compatibility/?utm_source=notice&utm_medium=product&utm_content=themecompatibility&utm_campaign=woocommerceplugin

2 回答

  • 1

    您可以覆盖单个产品模板 .

    要覆盖单个产品模板,请将:wp-content / plugins / woocommerce / templates / single-product复制到wp-content / themes / Builder / woocommerce / single-product

    有一个关于WooCommerce主题覆盖的官方文档,在Template Structure + overriding template s通过主题 .

  • 1

    感谢Lax,我找到了解决方法 . 我实际上使用了我从主题的page.php创建的woocommerce.php . 这是从产品所在的容器中取出的 .

    然后我使用 dynamic_sidebar('sidebar_name_here') 在该页面上显示侧边栏 . 我使用的完整代码是:

    <?php if(is_product()){?>
      <div class="store-sidebar-left">
        <?php dynamic_sidebar('store-sidebar-left');?>
      </div>
    <?php } ?>
    

    这允许它仅显示在单个产品页面上 .

    我有一个小问题,在我的主题或我的数据库中找不到侧边栏的名称,所以我在我的functions.php文件中创建了一个新的并使用了那个 .

相关问题