wordpress woocommerce 模板文件覆盖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15025213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wordpress woocommerce template file overiding
提问by NewUser
I am using woocommerceto develop an ecommerce store. Everything is fine with woocommerce. But I have one problem. As because I want to show some custom images with some texts in the product page(shop based page). So for that I thought wordpress advanced custom fieldswill be good. I made it install. And now I need to extract the image in the template file. But by going through woocommerce plugin I got that it doesn't use the wordpress template. Woocommerce is generating the total page (producr page) by itself. And Iwant to show some custom fields from wordpress advanced custom fieldsplugin. So can someone kindly tell me how to do this? Any help and suggestions will be really appreciable. Thanks...
我正在使用woocommerce来开发电子商务商店。woocommerce 一切正常。但我有一个问题。因为我想在产品页面(基于商店的页面)中显示一些带有一些文本的自定义图像。因此,我认为wordpress 高级自定义字段会很好。我让它安装。现在我需要提取模板文件中的图像。但是通过使用 woocommerce 插件,我发现它不使用 wordpress 模板。Woocommerce 自己生成总页面(生产者页面)。我想从wordpress 高级自定义字段插件中显示一些自定义字段。那么有人可以告诉我如何做到这一点吗?任何帮助和建议将是非常可观的。谢谢...
I want that woocommerce shop page where all the products are shown should use my own custom template. So that I can use wordpress advanced custom fields code there
我希望显示所有产品的 woocommerce 商店页面应该使用我自己的自定义模板。这样我就可以在那里使用 wordpress 高级自定义字段代码
回答by pixelistik
In order to override a Woocommerce template from wp-content/plugins/woocommerce/templates
, create a file with the same name in wp-content/themes/<your theme>/woocommerce
. It will be used instead of the original one.
为了从 覆盖 Woocommerce 模板wp-content/plugins/woocommerce/templates
,请在wp-content/themes/<your theme>/woocommerce
. 它将被用来代替原来的。
If you look at one of the original template files, you will actually find this instruction in a comment at the top:
如果您查看原始模板文件之一,您实际上会在顶部的注释中找到此说明:
Override this template by copying it to yourtheme/woocommerce/single-product.php
通过将其复制到 yourtheme/woocommerce/single-product.php 来覆盖此模板
回答by Ennui
WooCommerce doesn't use normal template files from your theme (it uses the header and footer etc but the bulk of the actual interior content is split into a lot of Woo template files).
WooCommerce 不使用主题中的普通模板文件(它使用页眉和页脚等,但实际内部内容的大部分被拆分为许多 Woo 模板文件)。
You can copy the templates out of the plugins/woocommerce/templates
directory and move them to the themes/yourtheme/woocommerce
directory to override (just pick the ones you need).
您可以将模板复制出plugins/woocommerce/templates
目录并将它们移动到themes/yourtheme/woocommerce
要覆盖的目录(只需选择您需要的模板)。
A list of all the templates can be found here. A list of useful php hooks/filters to use for more advanced customization can be found here. Other useful resources are the CSS structure docand this list of conditional template tagsfor WC.
可以在此处找到所有模板的列表。可在此处找到用于更高级自定义的有用 php 挂钩/过滤器列表。其他有用的资源是CSS 结构文档和WC的条件模板标签列表。
There is kind of lackluster documentation for nitty-gritty theme development for WC so you will probably need to take some time to experiment with the templates in order to accomplish what you want, but it's decently commented and pretty easy to work with once you learn your way around.
对于 WC 的基本主题开发,有一些乏善可陈的文档,因此您可能需要花一些时间来试验模板以完成您想要的工作,但是一旦您学会了它,它就会得到很好的评论并且很容易使用绕道。
回答by newComer
For products page and any part of your site that shows products like home page or category page the code responsible for it exists in woocommerce-template.php line 29
对于产品页面和您网站的任何显示主页或类别页面等产品的部分,负责它的代码存在于 woocommerce-template.php 第 29 行
<?php if ( have_posts() ) : ?>
<?php do_action('woocommerce_before_shop_loop'); ?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action('woocommerce_after_shop_loop'); ?>
<?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php woocommerce_get_template( 'loop/no-products-found.php' ); ?>
<?php endif;
you can use hooks and filters to change some part or you can override the function itself in themes/yourtheme/woocommerce/functions.phpalso you can edited directly but this is not advisable as you will lose changes after any upgrade.
您可以使用钩子和过滤器来更改某些部分,或者您可以在themes/yourtheme/woocommerce/functions.php 中覆盖函数本身, 您也可以直接编辑,但这不是可取的,因为您将在任何升级后丢失更改。
Notice that in line 71 this function use template file content-product.php that is The template for displaying product content within loops and can be override by copying it to yourtheme/woocommerce/content-product.php
请注意,在第 71 行中,此函数使用模板文件 content-product.php,它是用于在循环中显示产品内容的模板,可以通过将其复制到yourtheme/woocommerce/content-product.php来覆盖
回答by halid beslic
I found a great list of free woocommerce plugins, and some customization tips. Maybe it will be of some help. http://fivera.net/woocommerce-customization-free-wp-plugins/
我找到了一个很棒的免费 woocommerce 插件列表,以及一些自定义技巧。也许它会有所帮助。 http://fivera.net/woocommerce-customization-free-wp-plugins/