-
-
Save fervous/fefb0712c20e958b294c04b58928acbb to your computer and use it in GitHub Desktop.
Show Vendors Products to Customers Following a Vendor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* https://www.wcvendors.com/help/reply/20920/ */ | |
function recent_products_test( ) { | |
$user_followings = bp_follow_get_following(); | |
foreach ($user_followings as $user_following ) { | |
$wcv_users[]= get_userdata( $user_following ); | |
} | |
foreach ($wcv_users as $wcv_user ) { | |
if ( $wcv_user->roles[0] == "vendor" ) { | |
$comma_wcv_user .= $wcv_user->ID . ','; | |
} | |
} | |
$final_wcv_user = rtrim($comma_wcv_user,','); | |
global $woocommerce_loop; | |
extract( shortcode_atts( array( | |
'per_page' => '12', | |
'vendor' => '', | |
'columns' => '3', | |
'orderby' => 'date', | |
'order' => 'desc' | |
), $atts ) ); | |
$meta_query = WC()->query->get_meta_query(); | |
$args = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'author' => $final_wcv_user, | |
'ignore_sticky_posts' => 1, | |
'posts_per_page' => $per_page, | |
'orderby' => $orderby, | |
'order' => $order, | |
'meta_query' => $meta_query | |
); | |
ob_start(); | |
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args ) ); | |
$woocommerce_loop['columns'] = $columns; | |
if ( $products->have_posts() ) : ?> | |
<?php woocommerce_product_loop_start(); ?> | |
<?php while ( $products->have_posts() ) : $products->the_post(); ?> | |
<?php wc_get_template_part( 'content', 'product' ); ?> | |
<?php endwhile; // end of the loop. ?> | |
<?php woocommerce_product_loop_end(); ?> | |
<?php endif; | |
wp_reset_postdata(); | |
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment