gpt4 book ai didi

php - 更改 "woocommerce_template_loop_product_title"标题标签

转载 作者:行者123 更新时间:2023-12-04 01:20:02 30 4
gpt4 key购买 nike

我正在尝试更改 WooCommerce woocommerce-loop-product__title来自 H2h6但我遇到了一些麻烦。
我使用下面的代码片段解开原始函数并将其替换为 h6 .不幸的是,这确实添加了 h6但它也保留了原来的h2 .
有人能指出这是哪里出了问题吗?

remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
add_action('woocommerce_shop_loop_item_title', 'soChangeProductsTitle', 10 );
function soChangeProductsTitle() {
echo '<h6 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h6>';
}

最佳答案

首先我们要申请一个 remove_action到现有标题。
优先10用于此目的(这是 WooCommerce 中的默认设置,请参阅附加的代码行)。
复制/粘贴自 /includes/wc-template-hooks.php第 98 行 @version 2.1.0

add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

但是,如果您使用的主题与 WooCommerce 中的默认行为不同,则优先级编号可能会有所不同(简而言之,这取决于主题)
然后我们将根据现有输出用我们想要的输出覆盖现有输出(我们刚刚删除)。现有的输出可以在我之前在回答中引用的同一个文件中找到,即第 1165 行 @version 2.1.0
所以你得到:
/**
* Show the product title in the product loop. By default this is an H2.
*/
function action_woocommerce_shop_loop_item_title() {
// Removes a function from a specified action hook.
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

echo '<h6 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h6>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
add_action( 'woocommerce_shop_loop_item_title', 'action_woocommerce_shop_loop_item_title', 9 );

关于php - 更改 "woocommerce_template_loop_product_title"标题标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62777942/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com