如何在没有插件的情况下自定义WooCommerce商店页面

发布于 2025-02-13 07:08:06 字数 2246 浏览 1 评论 0原文

我正在尝试完全在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' );

enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只等公子 2025-02-20 07:08:06

在您的孩子主题文件夹中,创建一个文件夹calle woocommerce anmd anmd在一个名为 archive-product.php 的文件中,这是商店页面模板文件,根据需要自定义。

示例:

do_action('woocommerce_before_shop_loop');
echo '<h1>MOST POPULAR PRODUCTS</h1>';
do_shortcode('[products orderby="popularity" class="m-popular" columns="2" limit="2"]'); do_action('woocommerce_after_shop_loop');

您可以解开的存档页面默认加载项列表:

add_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
 
add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
 
add_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
 
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); 
 
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
 
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
 
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
 
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
 
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
 
add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

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:

do_action('woocommerce_before_shop_loop');
echo '<h1>MOST POPULAR PRODUCTS</h1>';
do_shortcode('[products orderby="popularity" class="m-popular" columns="2" limit="2"]'); do_action('woocommerce_after_shop_loop');

List of default add-actions for archive page that you can unhook:

add_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
 
add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
 
add_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
 
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); 
 
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
 
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
 
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
 
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
 
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
 
add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文