ergoProxy
ergoProxy

Reputation: 93

Display vendor's products by category

I am using WooCommerce together with the WCFM Marketplace plugin. I’m trying to figure out a way to display the vendor's products under different categories, on the vendor’s store page.

For example:

VEGETABLES (category)

Product | Product | Product | Product

FRUITS (category)

Product | Product | Product | Product

I am aware they already feature a widget sidebar with the vendor's categories, but I would like to have sections on the page as shown above. In my head it be something like "for each vendor category -> display products in that category".

Upvotes: 0

Views: 884

Answers (1)

El Anas
El Anas

Reputation: 1

You can add this snippet to your child theme:

add_shortcode('wcfm_store_related_products','fn_wcfm_store_related_products');
function fn_wcfm_store_related_products($attr) {
    global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post;     
    $store_id = '';
    if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }

    if (  wcfm_is_store_page() ) {
        $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
        $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
        $store_id  = 0;
        if ( !empty( $store_name ) ) {
            $store_user = get_user_by( 'slug', $store_name );
        }
        $store_id           = $store_user->ID;
    }   
    if( is_product() ) {
        $store_id = $post->post_author;
    }
    if( !$store_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
        $store_id = $post->post_author;
    }
    echo do_shortcode('[products category="t-shirt" store="'.$store_id.'"]');
}

Usage by shortcode : [wcfm_store_related_products]

Upvotes: 0

Related Questions