最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How do I check if a product is in two categories?

programmeradmin0浏览0评论

Inside content-single-product.php, im using an if statement to find out what category each product is in, which I have working:

global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
                  
 if ( in_array( 'cat-1', $categories ) ) { ?>

  <h3>Category 1:</h3>
                    
 <?php } elseif ( in_array( 'cat-2', $categories ) ) { ?>
                    
 <h3>Category 2:</h3>

 <?php } else { ?>

 <h3>Bundle Products:</h3>
                                            
 <?php } ?>
                      

But some products are in multiple categories, so how can i decide what happens under these instances?

发布评论

评论列表(0)

  1. 暂无评论