evolve_woo_product

The evolve evolve woo product function.

Description

evolve_woo_product( $atts, (constant) $content = null ); 

Parameters (2)

0. $atts
The atts.
1. $content — Optional. (constant) => null
The content.

Usage

  1. if ( !function_exists( 'evolve_woo_product' ) ) { 
  2. require_once '/library/functions/basic-functions.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // The content. 
  8. $content = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = evolve_woo_product($atts, $content); 
  12.  

Defined (1)

The function is defined in the following location(s).

/library/functions/basic-functions.php  
  1. function evolve_woo_product($atts, $content = null) { 
  2. global $woocommerce_loop; 
  3.  
  4. if (empty($atts)) { 
  5. return; 
  6.  
  7. $args = array( 
  8. 'post_type' => 'product',  
  9. 'posts_per_page' => 1,  
  10. 'no_found_rows' => 1,  
  11. 'post_status' => 'publish',  
  12. 'meta_query' => array( 
  13. array( 
  14. 'key' => '_visibility',  
  15. 'value' => array('catalog', 'visible'),  
  16. 'compare' => 'IN' 
  17. ),  
  18. 'columns' => 1 
  19. ); 
  20.  
  21. if (isset($atts['sku'])) { 
  22. $args['meta_query'][] = array( 
  23. 'key' => '_sku',  
  24. 'value' => $atts['sku'],  
  25. 'compare' => '=' 
  26. ); 
  27.  
  28. if (isset($atts['id'])) { 
  29. $args['p'] = $atts['id']; 
  30.  
  31. ob_start(); 
  32.  
  33. if (isset($columns)) { 
  34. $woocommerce_loop['columns'] = $columns; 
  35.  
  36. $products = new WP_Query($args); 
  37.  
  38. if ($products->have_posts()) : 
  39.  
  40. woocommerce_product_loop_start(); 
  41.  
  42. while ($products->have_posts()) : $products->the_post(); 
  43.  
  44. woocommerce_get_template_part('content', 'product'); 
  45.  
  46. endwhile; // end of the loop.  
  47.  
  48. woocommerce_product_loop_end(); 
  49.  
  50. endif; 
  51.  
  52. wp_reset_postdata(); 
  53.  
  54. return '<div class="woocommerce">' . ob_get_clean() . '</div>';