attributes - 在商店页面上显示可用属性
问题描述
我想在主页上显示可用的属性。为此,我有这段代码,它可以工作,但它显示了所有属性,而不仅仅是可用的属性。
function display_shop_loop_product_attributes() {
global $product;
// Define you product attribute taxonomies in the array
$product_attribute_taxonomies = array( 'pa_size1', 'pa_size2', 'pa_faction', 'pa_gender' );
$attr_output = array(); // Initializing
// Loop through your defined product attribute taxonomies
foreach( $product_attribute_taxonomies as $taxonomy ){
if( taxonomy_exists($taxonomy) ){
$label_name = wc_attribute_label( $taxonomy, $product );
$term_names = $product->get_attribute( $taxonomy );
if( ! empty($term_names) ){
$attr_output[] = '<span class="'.$taxonomy.'">'.$label_nam.' '.$term_names.'</span>';
}
}
}
// Output
echo '<div class="product-attributes">'.implode( '<br>', $attr_output ).'</div>';
} ```
解决方案
推荐阅读
- node.js - 当我尝试发送 RichEmbed 时,Bot 发送一条空消息
- java - 为什么我不能在这个 while 循环中使用括号?
- objective-c - 检查 setImageWithURL 图像是否已加载或占位符图像已设置
- c# - 如何在类中添加图像列表?
- javascript - 如果选中复选框,则传递输入值,值在数组中?
- python - ipython3 和 jupyter notebook 不允许 python3 选项
- c# - Xamarin 表单 - 自定义 ContentPage 的工具栏项
- r - 将大量数字从 R 导出到 csv
- reactjs - 覆盖 onDrop 事件中断 ImageInput 预览
- reactjs - 使用查询组件 React apollo 设置状态