在WooCommerce中,可以通过自定义模板或使用插件来实现将环路产品类别项目说明显示在其标题下方。
首先,需要创建一个自定义模板文件,可以将其命名为single-product.php
。然后,在该模板文件中,可以使用WooCommerce提供的函数来获取产品的类别和说明信息,并将其显示在标题下方。
以下是一个示例代码:
<?php
/**
* WooCommerce单个产品模板
*/
defined( 'ABSPATH' ) || exit;
get_header( 'shop' );
while ( have_posts() ) :
the_post();
do_action( 'woocommerce_before_single_product' );
if ( post_password_required() ) {
echo get_the_password_form(); // 如果产品受密码保护,则显示密码表单
return;
}
?>
<div id="product-<?php the_ID(); ?>" <?php wc_product_class(); ?>>
<div class="product-info">
<h1 class="product-title"><?php the_title(); ?></h1>
<?php
// 获取产品类别
$categories = get_the_terms( get_the_ID(), 'product_cat' );
if ( $categories && ! is_wp_error( $categories ) ) {
echo '<div class="product-categories">';
foreach ( $categories as $category ) {
echo '<a href="' . get_term_link( $category->term_id, 'product_cat' ) . '">' . $category->name . '</a>';
}
echo '</div>';
}
// 获取产品说明
$description = get_the_content();
if ( $description ) {
echo '<div class="product-description">' . $description . '</div>';
}
?>
<div class="product-content">
<?php the_content(); ?>
</div>
</div>
</div>
<?php
do_action( 'woocommerce_after_single_product' );
endwhile;
get_footer( 'shop' );
以上代码会在产品标题下方显示产品类别和说明。可以根据需要进行样式调整和其他自定义。
领取专属 10元无门槛券
手把手带您无忧上云