Guest User

Untitled

a guest
Apr 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. $product = get_product();
  2. global $variable_id;
  3. global $color;
  4. if ($product->product_type == "variable") {
  5. $variations = $product->get_available_variations();
  6. foreach ($variations as $variation) {
  7. $color = $variation["attributes"]["attribute_pa_colour"];
  8. $variable_id = $variation['variation_id'];
  9. wc_get_template_part('content', 'product');
  10. }
  11. } else {
  12. $variable_id = null;
  13. $color = null;
  14. wc_get_template_part('content', 'product');
  15. }
  16.  
  17. private function query_products( $args ) {
  18. // Set base query arguments
  19. $query_args = array(
  20. 'fields' => 'ids',
  21. 'post_type' => 'product',
  22. 'post_status' => 'publish',
  23. 'meta_query' => array(),
  24. );
  25. if ( ! empty( $args['type'] ) ) {
  26. $types = explode( ',', $args['type'] );
  27. $query_args['tax_query'] = array(
  28. array(
  29. 'taxonomy' => 'product_type',
  30. 'field' => 'slug',
  31. 'terms' => $types,
  32. ),
  33. );
  34. unset( $args['type'] );
  35. }
  36.  
  37. // Filter products by category
  38. if ( ! empty( $args['category'] ) ) {
  39. $query_args['product_cat'] = $args['category'];
  40. }
  41.  
  42. // Filter by specific sku
  43. if ( ! empty( $args['sku'] ) ) {
  44. if ( ! is_array( $query_args['meta_query'] ) ) {
  45. $query_args['meta_query'] = array();
  46. }
  47. $query_args['meta_query'][] = array(
  48. 'key' => '_sku',
  49. 'value' => $args['sku'],
  50. 'compare' => '='
  51. );
  52. $query_args['post_type'] = array( 'product', 'product_variation' );
  53. }
  54. $query_args = $this->merge_query_args( $query_args, $args );
  55. return new WP_Query( $query_args );
  56. }
Add Comment
Please, Sign In to add comment