Guest User

Untitled

a guest
Oct 23rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2. $args = array( 'post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'books');
  3. $loop = new WP_Query( $args );
  4.  
  5.  
  6. $send_array = array();
  7. while ( $loop->have_posts() ) : $loop->the_post();
  8. global $product;
  9.  
  10. $send_array[] = array(
  11.  
  12. 'id' => get_the_ID(),
  13. 'title' => get_the_title(),
  14. 'content' => get_the_content(),
  15. 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
  16. 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
  17. 'weight' => woocommerce_get_product_terms($product->id, 'weight', 'names')
  18.  
  19. );
  20.  
  21. endwhile;
  22.  
  23. wp_reset_query();
  24. ob_clean();
  25. echo json_encode($send_array);
  26. exit();
  27.  
  28. ?>
  29.  
  30. $weight = woocommerce_get_product_terms($product->id, 'pa_weight', 'names');
  31.  
  32. $send_array[] = array(
  33.  
  34. 'id' => get_the_ID(),
  35. 'title' => get_the_title(),
  36. 'content' => get_the_content(),
  37. 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
  38. 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
  39. 'weight' => $weight[0]
  40.  
  41. );
  42.  
  43. $item_weight=wp_get_post_terms($post->ID, 'pa_weight', array("fields" => "names"));
  44.  
  45. $send_array[] = array(
  46.  
  47. 'id' => get_the_ID(),
  48. 'title' => get_the_title(),
  49. 'content' => get_the_content(),
  50. 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
  51. 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
  52. 'weight' => $item_weight[0]
  53.  
  54. );
  55.  
  56. $items = WC()->cart->get_cart();
  57. $x = 0;
  58. foreach($items as $item => $values) {
  59. $_product2 = $values['data'];
  60.  
  61. $getProductDetail = wc_get_product( $values['product_id'] );
  62.  
  63. echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
  64.  
  65.  
  66. $weight = $getProductDetail->product_attributes;
  67. echo 'Weight: '.$weight["weight"]["value"].'<br>';
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment