You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将WooCommerce按分类布局应用到Dokan商家店铺商品列表?

问题:Dokan商家商品列表无法应用WooCommerce分类布局

我使用Astra主题搭配WordPress和Dokan多供应商插件,WooCommerce店铺页面的按分类布局(对应PHP代码如下)可正常显示,但该布局无法应用到Dokan商家的商品列表中。我找到了渲染商家商品的脚本,但不知如何调整。

WooCommerce店铺页面PHP代码

<?php
add_action( 'woocommerce_no_products_found', 'bbloomer_show_4_products_per_category' );

function bbloomer_show_4_products_per_category() {
    $args = array(
        'parent' => 0,
        'hide_empty' => true,
        'taxonomy' => 'product_cat',
        'fields' => 'slugs',
    );
    $categories = get_categories( $args );
    foreach ( $categories as $category_slug ) {
        $term_object = get_term_by( 'slug', $category_slug , 'product_cat' );
        echo '<hr><h2>' . $term_object->name . '</h2>';
        echo do_shortcode( '[products limit="4" columns="4" category="' . $category_slug . '"]' );
        echo '<p><a href="' . get_term_link( $category_slug, 'product_cat' ) . '">View all ' . 
            $term_object->name . ' products &rarr;</a>';
    }
}
?>

Dokan商家商品渲染脚本

<?php do_action( "dokan_store_before_{$section_id}_product_section", $vendor ); ?>

<div id="dokan_store_section_<?php echo esc_attr( $section_id ); ?>" class="dokan-store-product-section">
    <h2 class="products-list-heading"><?php echo esc_html( $section_title ); ?></h2>
    <div class="seller-items">

        <?php woocommerce_product_loop_start(); ?>

            <?php while ( $products->have_posts() ) : $products->the_post(); ?>

                <?php wc_get_template_part( 'content', 'product' ); ?>

            <?php endwhile; ?>

        <?php woocommerce_product_loop_end(); ?>

        <?php wp_reset_postdata(); ?>

    </div>
</div>

<?php do_action( "dokan_store_after_{$section_id}_product_section", $vendor ); ?>

内容的提问来源于stack exchange,提问作者tyrese humphreys

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 11:03:27