如何在没有插件的情况下自定义WooCommerce商店页面
我正在尝试完全在WooCommerce中自定义shop
页面,但没有使用插件就看不到一种方法。
我想,如果我不设置shop
wooCommerce中的页面(例如,它只是一个带有模板的页面),那么我需要设置从商店页面重定向到我的新商店页面?
我期望的是,我可以像对其他模板一样将文件复制到我的主题(即WooCommerce/store.php)中来覆盖模板。但是,研究WooCommerce插件代码库,看起来整个loop
文件夹创建shop
page(woocommerce/woocommerce/templates/loop
)。
我可以简单地沿着创建自定义模板的路线(即Archive-Shop.php
),然后在需要时设置重定向。但是,想知道没有插件是否有一种更最佳的方法来执行此操作?
响应@hhh:
我已经在主题中添加了“ Archive-product.php”(WooCommerce/Archive-product.php
),并从原始文件粘贴WooCommerce
插件。
在我复制的版本中,我将标题更改为“这是一个测试”:
< h1 class =“ woocommerce-products-header__title page-title”>这是一个测试</h1>
i甚至进一步拆除了文件以仅展示h1
,但不会从插件中覆盖默认模板:
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.4.0
*/
defined( 'ABSPATH' ) || exit;
get_header( 'shop' );
do_action( 'woocommerce_before_main_content' );
?>
<header class="woocommerce-products-header">
<h1 class="woocommerce-products-header__title page-title">THIS IS A TEST</h1>
</header>
<?php
get_footer( 'shop' );
I'm trying to customise the shop
page in WooCommerce completely, but cannot see a way to do so without the use of plugins.
I imagine that if I do not set a shop
page in WooCommerce (and it's just a page with a template for example), then I would need to set up redirects from the shop page to my new store page?
What I was expecting was that I could simply override the template by copying the file into my theme (i.e. woocommerce/store.php) as I've done with other templates. However, looking into the WooCommerce plugin codebase, it looks like the entire loop
folder creates the shop
page (woocommerce/templates/loop
).
I can simply go down the route of create a custom template (i.e. archive-shop.php
) and set up the redirect if needed. But, wondering if there's a more optimal way to do this, without plugins?
In response to @hhh:
I have added "archive-product.php" to my theme (woocommerce/archive-product.php
), and pasted over the original file from the woocommerce
plugin.
In my copied version, I changed the header to "this is a test":
<h1 class="woocommerce-products-header__title page-title">THIS IS A TEST</h1>
I even further dismanted the file to only showcase the h1
, but it does't override the default template from the plugin:
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.4.0
*/
defined( 'ABSPATH' ) || exit;
get_header( 'shop' );
do_action( 'woocommerce_before_main_content' );
?>
<header class="woocommerce-products-header">
<h1 class="woocommerce-products-header__title page-title">THIS IS A TEST</h1>
</header>
<?php
get_footer( 'shop' );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的孩子主题文件夹中,创建一个文件夹calle woocommerce anmd anmd在一个名为 archive-product.php 的文件中,这是商店页面模板文件,根据需要自定义。
示例:
您可以解开的存档页面默认加载项列表:
In your child theme folder create a folder calle WooCommerce anmd inside a file called archive-product.php which is the shop page template file, customize it as desired.
example:
List of default add-actions for archive page that you can unhook: