Hello. There is a wordpress website with a WooCommerce plugin, the site has products with a price. The question is how to display the product and its price in php or where in the WooCommerce plugin in the database is the product stored with the price?

I am trying to bring the goods like this:

$args = array( 'post_type' => array( 'product' ), 'post_status' => array( 'publish' ), 'nopaging' => true, ); $query = new WP_Query; $my_posts = $query->query($args); print_r ($my_posts); 

but in the variable my_posts the price of the product is not, there is a name, status, date of publication, a description. Picture 1. enter image description here

2 answers 2

Hello.

Metadata is stored.

 $price = get_post_meta( get_the_ID(), '_regular_price', true); $sale = get_post_meta( get_the_ID(), '_sale_price', true); 

http://wpcheatsheet.net/woocommerce-get-price-in-custom-loop/

    It is not necessary to climb into the base. On all there are functions WooCommerce. In this case, you need to create a WC_Product object based on the post number and get prices from it:

     foreach ($my_posts as $my_post) { $product = new WC_Product($my_post->ID); echo $product->get_regular_price(); echo $product->get_sale_price(); echo $product->get_price(); }