简体   繁体   English

WooCommerce:供应商的产品循环?

[英]WooCommerce: Product Loop by Vendor?

I managed to get the store names of all of the current vendors to display in a <ul> tag but it seems that when I loop to get the products, all of the products registered gets displayed under the store name.  

How would I go about getting the products that are unique to the store name? 

This is a WordPress, woocommerce and dokan project.这是一个 WordPress、woocommerce 和 dokan 项目。

User Story;用户的故事;

As a user, I'll see the vendor's store name and will be able to see all of the vendor's products underneath the vendor's store name.作为用户,我将看到供应商的商店名称,并且能够在供应商的商店名称下看到供应商的所有产品。

<div id="dokan-seller-listing-wrap">
    <div class="seller-listing-content">
        <?php if ( $sellers['users'] ) : ?>
            <ul class="dokan-seller-wrap">
                <?php
                foreach ( $sellers['users'] as $seller ) {
                    $store_info_author      = dokan_get_store_info( $post->post_author );
                    $store_info             = dokan_get_store_info( $seller->ID );
                    $store_name             = isset( $store_info['store_name'] ) ? esc_html( $store_info['store_name'] ) : __( 'N/A', 'dokan-lite' );
                    $store_url              = dokan_get_store_url( $seller->ID );
                    $featured_seller        = get_user_meta( $seller->ID, 'dokan_feature_seller', true );

                    ?>
        <div class="row">
            <div class="col-md-12">
            <div class="store-data">
                    <h2><a href="<?php echo esc_attr($store_url); ?>"><?php echo esc_html($store_name); ?></a></h2>
            </div>
            </ul>
                <li class="slides">
                    <?php
                    $args = array(
                              'post_type' => 'product', 
                              'posts_per_page' => 12
                                    );

                                        $loop = new WP_Query( $args );
                                        if ($sellers['users']) {
                                            while ( $loop->have_posts() ) : $loop->the_post();
                                                wc_get_template_part( 'content','product' );
                                            endwhile;
                                        } else {
                                            echo __( 'No products found' );
                                        }
                                        wp_reset_postdata();
                                    ?>
                </li><!--/.products-->

                    <?php } ?>
           </div>                   
        </div>           
    </div>
</div>

You need to specify author in your WP_Query arguments something like given below您需要在WP_Query参数中指定作者,如下所示

$args = array(
 'author'  => $seller->ID,
 'post_type' => 'product', 
 'posts_per_page' => 12
);

 $loop = new WP_Query( $args );

 while ( $loop->have_posts() ) : $loop->the_post();
   wc_get_template_part( 'content','product' );
 endwhile;

 wp_reset_postdata();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM