我已经开始学习如何使用WooCommerce创建模板,我遇到了一个小问题 . 例如,在Woocommerce插件的php文件content-single-product.php中,我有这样的字符串:
<?php
/**
* woocommerce_single_product_summary hook.
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
do_action( 'woocommerce_single_product_summary' );
?>
例如,当我想编辑它(删除一些字段并更改结构)时,我尝试删除字符串:
do_action('woocommerce_single_product_summary');
之后写这样:
<?php
/**
* woocommerce_single_product_summary hook.
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
//do_action( 'woocommerce_single_product_summary' );
do_action('woocommerce_template_single_title');
?>
你能告诉我为什么这不起作用?
这样编辑的正确方法是什么?
谢谢
1 回答
在您的第一个代码段中,正如您在 woocommerce_single_product_summary hook 中看到的那样,您在 hook location 中使用 do_action() WordPress函数的所有不同模板 @hooked :
因此,在您的自定义代码(第二个代码片段)中,您刚刚用 hooked template slug (即 NOT 一个钩子)替换了 hook ,并且 NOT 将作为入口点 action hook . 请参阅本答案底部的参考文献list of WooCommerce actions and filters existing hooks ...
Explanations (How to):
隐藏的模板(优先顺序号)=>相应的模板文件名:
然后你需要编辑位于单一产品(子文件夹)中的相应的woocommerce_single_product_summary hook title.php ...一旦我们理解了模板结构文件和模板中的钩子,最后就不那么复杂了 . 优先级编号,给出了钩子模板的顺序:首先小,最后大......
另见:Hooks and their hooked functions execution queue in Wordpress and Woocommerce
Others ways:
Example using add_action() WordPress function:
参考文献:
Template Structure + Overriding Templates via a Theme
Hooks: Action and Filter reference
LIST of WooCommerce Action and Filter (Hook Reference)
Template Structure + Overriding Templates via a Theme
WooCommerce Visual Hook Guide: Single Product Page