WooCommerce-在哪里可以编辑钩子生成的HTML? [英] WooCommerce - where can I edit HTML generated by hooks?

查看:118
本文介绍了WooCommerce-在哪里可以编辑钩子生成的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WooCommerce的新手。无论如何,我想创建自己的主题,因此我遵循了指导原则,并将整个核心模板文件复制到了 / mywordpresstheme / woocommerce /

I'm new to WooCommerce. Anyhow, I want to create my own theme, so I followed the guidelines and copied accross the core template files to /mywordpresstheme/woocommerce/.

一切正常,我正在编辑模板。

That all works great and I'm editing the templates just fine.

但是,WooCommerce中的挂钩和操作方式使我感到困惑而且我无法确定生成的HTML的某些部分来自何处。

However, the way hooks and actions work in WooCommerce is baffling me and I can't work out where certain parts of generated HTML are coming from.

例如,在 content-product.php ,有一个获取图像的钩子:

For example, in content-product.php, there is a hook that gets the image:

<?php
/*
* woocommerce_before_shop_loop_item_title hook
*
* @hooked woocommerce_show_product_loop_sale_flash - 10
* @hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?>

但这是什么?它从何而来??动作名称中是否有关于我可以定位生成的HTML以进行编辑的线索?

But what is this? Where does it come from?? Is there any clue in the action name as to where I could locate the HTML being generated for the purpose of editing it?

我已经阅读了有关挂钩和过滤器在WooCommerce上使用,但它并没有说明根据具体情况在何处或如何更改它们。

I've read the article on 'hooks and filters' on WooCommerce, but it explains nothing regarding where or how to change these on a case for case basis.

任何帮助将不胜感激。

我是这个系统的新手,我敢肯定我只是在忽略一些非常明显的东西。

I'm new to this system and I'm sure I'm simply over-looking something very obvious.

谢谢,
Mikey。

Thanks, Mikey.

推荐答案


但这是什么?它从何而来??
动作名称中是否有关于我可以定位为
生成的HTML以进行编辑的地方的线索?

But what is this? Where does it come from?? Is there any clue in the action name as to where I could locate the HTML being generated for the purpose of editing it?

这是一个动作挂钩。它本身并没有做任何事情,但注释 hook 中列出的功能已插入其中,因此在触发该功能时运行。它在注释中说,函数 woocommerce_template_loop_product_thumbnail 是负责获取缩略图的函数。您可以在Woocommerce插件中找到此功能。我使用Sublime Text编辑器(尽管我认为其他人也会这样做),在整个文件夹中搜索该短语,它会告诉我确切的文件位置。在这种情况下,这就是所谓的可插入函数,它位于 woocommerce-template.php 。 (在2.1+版中现在称为wc-template-hooks.php)

This is an action hook. It isn't doing anything by itself per say, but the functions listed in the comments hook into it and therefore run when this function is triggered. It says in the comments that function woocommerce_template_loop_product_thumbnail is the function responsible for getting the thumbnail. You can find this function inside the Woocommerce plugin. I use the Sublime Text editor (though I think others will do this too) to search the whole folder for that phrase and it tells me exactly what file it is in. In this case it is what is called a pluggable function and is located in woocommerce-template.php. (It's now called wc-template-hooks.php in version 2.1+)

可插拔函数意味着您在自己的名称中定义了该函数的新版本主题的functions.php

A pluggable function means that you define a new version of the function with the same name in your theme's functions.php

function woocommerce_template_loop_product_thumbnail(){
  echo "apple";
}

如果将上述内容放入您的functions.php中,则代替Woo的 woocommerce_template_loop_product_thumbnail()您只会看到苹果这个词。

If you put the above in your functions.php then instead of Woo's woocommerce_template_loop_product_thumbnail() you'd merely see the word apple.


我已经阅读了WooCommerce上有关挂钩和过滤器的文章,但其中
并没有说明有关在何处或如何进行

I've read the article on 'hooks and filters' on WooCommerce, but it explains nothing regarding where or how to change these on a case for case basis.

您将在主题的functions.php和一个案例中进行所有更改。无需根据情况。所有的钩子和过滤器的行为都相同。也就是说,它们不是最容易学习的东西,因此要对自己有耐心。我发现过滤器很难缠住我的头。

You will make all changes in your theme's functions.php and a case by case basis isn't necessary. All hooks and filters behave the same. That said, they aren't the easiest thing to learn so have patience with yourself. I found filters to be especially tough to wrap my head around.

在一些无用的自我推广中,我在 WordPress钩子和过滤器的基础(一篇文章说它是用于主题钩子,但是钩子是钩子!)我希望人们在我的WordPress职业生涯开始时就告诉我。

In a spot of gratuitous self-promotion I wrote a series of articles on the basics of WordPress hooks and filters (one article says it is for Thematic hooks, but a hook is a hook! ) that are all the things I wish people had told me at the beginning of my WordPress career.

这篇关于WooCommerce-在哪里可以编辑钩子生成的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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