Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_after_single_product_summary', 'woocommerce_after_single_product_summary_callback');
- function woocommerce_after_single_product_summary_callback() {
- $product_id = get_the_ID();
- $author_id = get_post($product_id)->post_author;
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- 'author' => $author_id
- );
- $loop = new WP_Query($args);
- if ($loop->have_posts()) {
- while ($loop->have_posts()) : $loop->the_post();
- add_filter('transient_wc_related_' . get_the_ID(), 'wc_related_callback');
- endwhile;
- }
- wp_reset_postdata();
- }
- function wc_related_callback($values) {
- $product_id = get_the_ID();
- $author_id = get_post($product_id)->post_author;
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- 'author' => $author_id
- );
- $vendor_products = array();
- $related_array = array();
- $loop = new WP_Query($args);
- if ($loop->have_posts()) {
- while ($loop->have_posts()) : $loop->the_post();
- $vendor_products[] = get_the_ID();
- endwhile;
- }
- if (!empty($vendor_products)) {
- foreach ($vendor_products as $vendor_product) {
- $related_array[] = $vendor_product;
- }
- }
- if (!empty($values)) {
- foreach ($values as $value) {
- $related_array[] = $value;
- }
- }
- wp_reset_postdata();
- return $related_array;
- }
Add Comment
Please, Sign In to add comment