php - 显示带有标题的子类别 WooCommerce 产品
问题描述
我将 woocommerce 产品的显示更改为在商店循环中显示为表格,而不是列元素。当我转到“商店”页面时,它会在列表中显示所有产品。我无法以有组织的方式展示产品,将产品分成相应的子类别。提前致谢!
解决方案
/**
* @snippet WooCommerce Show Product Subcategories
* @compatible WooCommerce 3.4
*/
add_action(
'woocommerce_after_shop_loop_item_title','bbloomer_show_all_subcats', 2 );
function bbloomer_show_all_subcats() {
// Create array with product categories that belong to current product
$cats = get_the_terms( $post->ID, 'product_cat' );
if ( ! empty( $cats ) ) {
// Loop through the product categories...
foreach ( $cats as $term ) {
// If parent cat ID = 116 echo subcat name...
if( $term->parent == 116 ) { echo $term->name; }
}
}
}
推荐阅读
- huawei-mobile-services - 谷歌和华为 APK 风格构建问题
- angular - 如何在 Angular ngForm 和组件 ts 中发布数据
- java - 在java中使用bufferedreader输入输入时出错
- javascript - 我们如何在正则表达式中替换 span contenteditable?
- java - meridiem 由设备本地语言而不是上午/下午给出
- html - 使用类选择 div 的前五个元素
- sql-server - 通过使用带有 where 子句的特定条件进行添加和分组
- spring-boot - 用于 Spring Boot 应用程序的 Intellij IDEA 中缺少映射
- powerbi-desktop - PowerBI-DirectQuery - 将时间与日期时间分开
- python - Python:如何根据另一个 list_of_lists 对 list_of_lists 进行排序?