Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $args = array( 'post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'books');
- $loop = new WP_Query( $args );
- $send_array = array();
- while ( $loop->have_posts() ) : $loop->the_post();
- global $product;
- $send_array[] = array(
- 'id' => get_the_ID(),
- 'title' => get_the_title(),
- 'content' => get_the_content(),
- 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
- 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
- 'weight' => woocommerce_get_product_terms($product->id, 'weight', 'names')
- );
- endwhile;
- wp_reset_query();
- ob_clean();
- echo json_encode($send_array);
- exit();
- ?>
- $weight = woocommerce_get_product_terms($product->id, 'pa_weight', 'names');
- $send_array[] = array(
- 'id' => get_the_ID(),
- 'title' => get_the_title(),
- 'content' => get_the_content(),
- 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
- 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
- 'weight' => $weight[0]
- );
- $item_weight=wp_get_post_terms($post->ID, 'pa_weight', array("fields" => "names"));
- $send_array[] = array(
- 'id' => get_the_ID(),
- 'title' => get_the_title(),
- 'content' => get_the_content(),
- 'regular_price' => get_post_meta( get_the_ID(), '_regular_price', true),
- 'sale_price'=> get_post_meta( get_the_ID(), '_sale_price', true),
- 'weight' => $item_weight[0]
- );
- $items = WC()->cart->get_cart();
- $x = 0;
- foreach($items as $item => $values) {
- $_product2 = $values['data'];
- $getProductDetail = wc_get_product( $values['product_id'] );
- echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
- $weight = $getProductDetail->product_attributes;
- echo 'Weight: '.$weight["weight"]["value"].'<br>';
- }
Advertisement
Add Comment
Please, Sign In to add comment