rimpa

Related Product Of Vendor And Related Product Of shop

Jul 6th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. add_action('woocommerce_after_single_product_summary', 'woocommerce_after_single_product_summary_callback');
  2.  
  3. function woocommerce_after_single_product_summary_callback() {
  4. $product_id = get_the_ID();
  5. $author_id = get_post($product_id)->post_author;
  6. $args = array(
  7. 'post_type' => 'product',
  8. 'posts_per_page' => -1,
  9. 'author' => $author_id
  10. );
  11. $loop = new WP_Query($args);
  12. if ($loop->have_posts()) {
  13. while ($loop->have_posts()) : $loop->the_post();
  14. add_filter('transient_wc_related_' . get_the_ID(), 'wc_related_callback');
  15. endwhile;
  16. }
  17. wp_reset_postdata();
  18. }
  19. function wc_related_callback($values) {
  20. $product_id = get_the_ID();
  21. $author_id = get_post($product_id)->post_author;
  22. $args = array(
  23. 'post_type' => 'product',
  24. 'posts_per_page' => -1,
  25. 'author' => $author_id
  26. );
  27. $vendor_products = array();
  28. $related_array = array();
  29. $loop = new WP_Query($args);
  30. if ($loop->have_posts()) {
  31. while ($loop->have_posts()) : $loop->the_post();
  32. $vendor_products[] = get_the_ID();
  33. endwhile;
  34. }
  35. foreach($vendor_products as $vendor_product){
  36. $related_array[] = $vendor_product;
  37. }
  38. foreach ($values as $value){
  39. $related_array[] = $value;
  40. }
  41. wp_reset_postdata();
  42. return $related_array;
  43. }
Add Comment
Please, Sign In to add comment