我有一个用于WooCommerce的自定义产品页面,该页面在其各自的类别标题下显示产品列表。您可以在此处查看页面:https://libertymachinery.com/inventory/
我需要对产品列表做两件事:
由于这不是商店页面,所以我不确定如何在需要它的位置调用SKU。我不介意在产品标题的末尾随处显示SKU,但我不想将其添加到每个帖子的实际标题中。
我能够在项目标题中添加项目符号,但无法弄清楚如何将其添加到产品标题中。这是我用于页面该部分的代码。
<!-- section -->
<section>
<?php
$args = array(
'taxonomy' => "product_cat",
'orderby' => 'title',
'order' => 'ASC',
'hide_empty' => true/* ,
'include' => $ids */
);
$product_categories = get_terms($args);
foreach($product_categories as $product_category){
$args = array(
'post_type' => 'product',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $product_category->slug
)
),
);
$loop = new WP_Query( $args );
if($product_category->count > 0){
$count_h = 0;
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$count_h ++;
if($product->catalog_visibility == 'visible'){
if($count_h == 1){
echo "<br><a href='".get_category_link($product_category->term_id)."'><strong style='text-transform: uppercase;'><li>".$product_category->name.'</li></strong></a><br>';
}
echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br />';
}
endwhile;
}
wp_reset_query();
}