Vendor Products short code

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 3 reply threads
  • Author
    Posts
    • #128074
      crzy4prple
      Participant

      Is there a short code to display products by vendor?

    • #128371

      Hello,

      Add this code to your child theme’s functions.php

      In case you do not have child theme then add code using this plugin – https://wordpress.org/plugins/code-snippets/

      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 store="'.$store_id.'"]');
      }

      After that you can use “[wcfm_store_related_products]” shortcode

      Thanks.

    • #128461
      crzy4prple
      Participant

      Thank you so much!!! works perfectly!! is there a way to limit how many products display?

    • #128816

      Hello,

      Yes, you can. Then use like – [wcfm_store_related_products id=<vendor id> limit=4]
      And modify the code –

      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;
      	}
      
      	if ( isset( $attr['limit'] ) && !empty( $attr['limit'] ) ) { 
      		$limit = absint($attr['limit']); 
      		echo do_shortcode('[products store="'.$store_id.'" limit="'.$limit.'"]');
      	} else {
      		echo do_shortcode('[products store="'.$store_id.'"]');
      	}
      
      	
      }

      Thanks.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.