Archive-Product.php(主商店页面)的 WooCommerce 模板覆盖不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18598716/
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
WooCommerce Template Override for Archive-Product.php (Main Shop Page) Not Working
提问by RyanMac
I can't for the life of me manage to override the main shop page.
我一辈子都无法覆盖主商店页面。
My understanding is that it's archive-product.php
我的理解是它是 archive-product.php
I've attempted to copy it into the Woocommerce directory I created in my theme's root directory and modify it. No dice.
我试图将它复制到我在主题根目录中创建的 Woocommerce 目录中并对其进行修改。没有骰子。
I've also attempted to modify it directly in the Woocommerce plugin directory. No dice there either.
我还尝试直接在 Woocommerce 插件目录中修改它。那里也没有骰子。
I've even gone as far as adding an underscore before the archive-product.php file name in both locations (woocommerce directory and my theme template directory) in an attempt to hopefully BREAK it - just to see if I could impact SOME change - and that doesn't seem to have any effect either.
我什至在两个位置(woocommerce 目录和我的主题模板目录)的 archive-product.php 文件名之前添加了一个下划线,以期希望打破它 - 只是为了看看我是否可以影响一些更改 -这似乎也没有任何影响。
I'm not running any cache plugins and every other Woocommerce template file I've attempted to modify up until this point has worked fine.
在此之前,我没有运行任何缓存插件和我尝试修改的所有其他 Woocommerce 模板文件。
Any ideas?
有任何想法吗?
回答by raison
You are doing this correctly. You'll have to double check the locations as per:
你这样做是正确的。您必须按照以下方式仔细检查位置:
Shop template is in
plugins/woocommerce/templates/archive-product.php
You can copy to
my-themes/woocommerce/archive-product.php
to override the core woocommerce file.
商店模板在
plugins/woocommerce/templates/archive-product.php
您可以复制到
my-themes/woocommerce/archive-product.php
以覆盖核心 woocommerce 文件。
回答by Dikeneko
I just had the same issue, What worked for me, is removing the woocommerce.php file, because before, it applied the template woocommerce.php to the shop, and not the archive-product.
我只是遇到了同样的问题,对我有用的是删除 woocommerce.php 文件,因为之前,它将模板 woocommerce.php 应用于商店,而不是存档产品。
回答by Somethumb
The answer is that when you updated to the newest version of WooCommerce, you have to "reinstall" the WooCommerce pages because the old system did not use the wc_get_page_id()
function, which looks for the shop page.
答案是,当您更新到最新版本的 WooCommerce 时,您必须“重新安装”WooCommerce 页面,因为旧系统没有使用wc_get_page_id()
查找商店页面的功能。
Luckily this is super easy! Go to your admin, then to WooCommerce, then to System Status, then click on the Tools tab. Then click the button to the right of Install WooCommerce Pages. This will only install the missing WooCommerce pages and, get this, will reinstall the shop page with the proper wc_get_page_id
.
幸运的是,这非常容易!转到您的管理员,然后转到 WooCommerce,然后转到系统状态,然后单击工具选项卡。然后单击安装 WooCommerce 页面右侧的按钮。这只会安装缺少的 WooCommerce 页面,并且获取此信息后,将使用正确的wc_get_page_id
.
NOTE: if you have content in the original WordPress shop page, although it didn't erase it for me, you might just want to copy the content first just in case.
注意:如果您在原始 WordPress 商店页面中有内容,虽然它没有为我删除它,您可能只想先复制内容以防万一。
回答by RCNeil
I was able to fix this by using the suggestion here - Changes on archive-product.php doesn't work
我能够通过使用这里的建议来解决这个问题 -对 archive-product.php 的更改不起作用
but, it seems like a bug to me. WooCommerce claims that you need that root woocommerce.php
page in order to incorporate the plugin into your custom theme - http://docs.woothemes.com/document/third-party-custom-theme-compatibility/- but, this does work.
但是,这对我来说似乎是一个错误。WooCommerce 声称您需要该根woocommerce.php
页面才能将插件合并到您的自定义主题中 - http://docs.woothemes.com/document/third-party-custom-theme-compatibility/- 但是,这确实有效。
I'd love to know the reasoning behind this.
我很想知道这背后的原因。
Switching to the twentyeleve/twentytwelve theme's and trying to override the archive-product.php
file in the same fashion worked great, but they don't include a native woocommerce.php
file in their root directory either. What gives?
切换到 twentyeleve/twentytwelve 主题并尝试以archive-product.php
相同的方式覆盖文件效果很好,但它们woocommerce.php
的根目录中也不包含本机文件。是什么赋予了?