rimpa

Related Product Of Vendor And Related Product Of shop

Jul 11th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 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.  
  20. function wc_related_callback($values) {
  21. $product_id = get_the_ID();
  22. $author_id = get_post($product_id)->post_author;
  23. $args = array(
  24. 'post_type' => 'product',
  25. 'posts_per_page' => -1,
  26. 'author' => $author_id
  27. );
  28. $vendor_products = array();
  29. $related_array = array();
  30. $loop = new WP_Query($args);
  31. if ($loop->have_posts()) {
  32. while ($loop->have_posts()) : $loop->the_post();
  33. $vendor_products[] = get_the_ID();
  34. endwhile;
  35. }
  36. if (!empty($vendor_products)) {
  37. foreach ($vendor_products as $vendor_product) {
  38. $related_array[] = $vendor_product;
  39. }
  40. }
  41. if (!empty($values)) {
  42. foreach ($values as $value) {
  43. $related_array[] = $value;
  44. }
  45. }
  46.  
  47. wp_reset_postdata();
  48. return $related_array;
  49. }
Add Comment
Please, Sign In to add comment