在 woocommerce 产品页面中用类别描述替换类别名称
我正在尝试使用以下脚本将类别名称替换为类别描述(仅当类别描述不为空时):
add_action( 'woocommerce_archive_description', 'bbloomer_show_all_subcats', 2 );
function bbloomer_show_all_subcats() {
global $product;
$cats = get_the_terms( $product->get_id(), 'product_cat' );
$cat_descr = join('', wp_list_pluck($cats, 'description'));
$categ = join('', wp_list_pluck($cats, 'name'));
if ($cat_descr){
echo '<div class="mf-catalog-title">'.$cat_descr.'</div>';
} else {
echo '<div class="mf-catalog-title">'.$categ.'</div>';
}
}
该脚本正在运行,但是当我在两个类别中有相同的产品时,类别名称会重复。当我有类别描述时,不会重复。只需类别名称即可。为什么会发生这种情况?
主题显示了他自己的类别名称,但我用一些 CSS 隐藏了它。哪个 php 钩子 (remove_action) 会消失类别名称?
谢谢。
I'm trying to replace the category name with category description (only if category description is not empty) with the below script:
add_action( 'woocommerce_archive_description', 'bbloomer_show_all_subcats', 2 );
function bbloomer_show_all_subcats() {
global $product;
$cats = get_the_terms( $product->get_id(), 'product_cat' );
$cat_descr = join('', wp_list_pluck($cats, 'description'));
$categ = join('', wp_list_pluck($cats, 'name'));
if ($cat_descr){
echo '<div class="mf-catalog-title">'.$cat_descr.'</div>';
} else {
echo '<div class="mf-catalog-title">'.$categ.'</div>';
}
}
The script is working but when I have same products in two categories, the category name is duplicating. When I have a category description, is not duplicating. Only the category name does it. Why does this happen?
The theme displays from his own the category name, but I hide this with some CSS. Which php hook (remove_action) disappears the category name?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了解决方案。
i found the solution myself.