【发布时间】:2020-06-24 00:33:40
【问题描述】:
我有一个要覆盖 WooCommerce 函数的子主题。
插件位置中的 WooCommerce 文件:woocommerce/includes/wc-template-hooks.php。我在子主题的同一层次结构中创建了一个新文件,它位于:my-child-theme/woocommerce/includes/wc-template-hooks.php
我编辑的部分是我在子主题中注释掉了产品标题:
/**
* Product Summary Box.
*
* @see woocommerce_template_single_title()
* @see woocommerce_template_single_rating()
* @see woocommerce_template_single_price()
* @see woocommerce_template_single_excerpt()
* @see woocommerce_template_single_meta()
* @see woocommerce_template_single_sharing()
*/
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); //commented
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
但是,当我转到我的产品页面时,我仍然看到标题。
知道我做错了什么吗?
【问题讨论】:
-
你确定
woocommerce/includes/wc-template-hooks.php是正确的吗?如果是这样,那就是您的问题,因为您只能覆盖 woocommerce 的templates目录中的文件。 -
谢谢,为什么我们不能编辑
includes目录?但不管我更新了template/single-product/目录中的title.php,但我也看不到更改。 -
你的目录结构是什么?
template目录需要在您的主题中的woocommerce目录中完全匹配:docs.woocommerce.com/document/template-structure -
您的子主题中不需要
templates。路径应该是yourtheme\woocommerce\single-product\title.php。 -
是的,您只能覆盖
templates目录。但如果需要,您也可以通过钩子进行更改。祝你好运!
标签: php wordpress woocommerce