在 WooCommerce 产品类别档案中的标题前显示描述 [英] Display description before the title in WooCommerce product category archives

查看:44
本文介绍了在 WooCommerce 产品类别档案中的标题前显示描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WooCommerce 中,我试图在产品类别存档页面中的标题之前显示描述.但是我没有尝试找出我可以使用什么钩子来做到这一点.

In WooCommerce, I am trying to display the description before the title in Product category archive pages. But I fail trying to find out what hooks could I use to do it.

我们的想法是先显示风味菜单",然后显示标题,如下图所示:

The idea was to have a "Flavour Menu" be displayed first, and then the title afterwards, like in this screenshot:

感谢任何曲目.

推荐答案

您需要覆盖位于 Woocommerce 插件中的模板 templates/archive-product.php,将其复制到您的活动主题文件夹到 woocommerce 子文件夹 (但不在 templates 子文件夹中).

You will need to override the template templates/archive-product.php located in the Woocommerce plugin, copying it to your active theme folder to a woocommerce subfolder (but not in atemplatessubfolder).

阅读官方相关文档:模板结构&通过主题覆盖模板

完成后,打开/编辑它并替换:

Once done, open / edit it and replace:

?>
<header class="woocommerce-products-header">
    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
        <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
    <?php endif; ?>

    <?php
    /**
     * Hook: woocommerce_archive_description.
     *
     * @hooked woocommerce_taxonomy_archive_description - 10
     * @hooked woocommerce_product_archive_description - 10
     */
    do_action( 'woocommerce_archive_description' );
    ?>
</header>
<?php

具有以下(我们在标题前添加自定义钩子):

?>
<header class="woocommerce-products-header">
    <?php 
    /**
     * Custom Hook: woocommerce_custom_archive_description.
     *
     * @hooked woocommerce_taxonomy_archive_description - 10
     */
    do_action( 'woocommerce_custom_archive_description' ); ?>

    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
        <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
    <?php endif; ?>

    <?php
    /**
     * Hook: woocommerce_archive_description.
     *
     * @hooked woocommerce_product_archive_description - 10
     */
    do_action( 'woocommerce_archive_description' );
    ?>
</header>
<?php

然后保存...

现在您将在您的活动子主题(或活动主题)的 function.php 文件中添加以下内容,我们将从默认挂钩中取消产品类别描述的挂钩,以将其挂钩我们新的自定义钩子(在标题之前):

Now you will add the following in the function.php file of your active child theme (or active theme), where we will unhook the product category description from the default hook, to hook it in our new custom hook (before the title):

remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_custom_archive_description', 'woocommerce_taxonomy_archive_description', 10 );

保存,大功告成……经过测试,有效.

Save, you are done… Tested and works.

这篇关于在 WooCommerce 产品类别档案中的标题前显示描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆