Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Marketplace › Vendor Products short code
Tagged: short code, vendor, WC Marketplace
- This topic has 3 replies, 2 voices, and was last updated 4 years, 6 months ago by Sarmistha Chakraborty.
Viewing 3 reply threads
- AuthorPosts
- May 7, 2020 at 8:10 pm #128074crzy4prpleParticipant
Is there a short code to display products by vendor?
- May 8, 2020 at 3:49 pm #128371Sarmistha ChakrabortyMember
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.
- May 8, 2020 at 8:24 pm #128461crzy4prpleParticipant
Thank you so much!!! works perfectly!! is there a way to limit how many products display?
- May 9, 2020 at 2:59 pm #128816Sarmistha ChakrabortyMember
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.
- AuthorPosts
Viewing 3 reply threads
- You must be logged in to reply to this topic.