I have created the code to loop through the product list and display the price

  $args = array( 'post_type' => 'product', 'posts_per_page' => 100, 'product_cat' => 'hot-deals');
          $loop = new WP_Query( $args );
          while ( $loop->have_posts() ) : $loop->the_post(); 

global $product; 

$xml .= '<Original_price>' . $product->get_display_price( $product->get_regular_price() ) . '</Original_price>';
$xml .= '<Discount_price>' . $product->get_display_price() . '</Discount_price>';

echo $product->get_price_html();


get_price_html() works perfectly and display the price like this:

From: $ 621 $ 559

However , I would like to get the price separately

I can get the sales price with


The problem is, I can not get the original price,

I tried $product->get_regular_price() , that return nothing

And I tried $product->get_display_price( $product->get_regular_price() ), that return the sales price

So how to get the original price ? Thanks a lot.

2 Answers 2


I'm pretty sure that the problem is, that the WP_Query returns post objects, which are not identical to Woocommerces product objects. While you are trying to get the product data by getting the according global, that won't work, especially because the query you are performing does nothing to that global. Now what I probably would do is, firstly, performing the query with the fields parameter set to ids. Secondly, when looping over the returned array of ids, I would suggest you get the product object with wc_get_product(), which should give you all the information you need.

Note: I answered this to enlighten about the difference in return between WordPress' and Woocommerces object. And to make clear, while product is a CPT it isn't necessarily optimally usable with WP's standard query. There is a strong argument though for your question being off topic, because it is about a third party plugin. Please take a look at our help center to learn more about our site guidelines.


To get the regular price inside the loop you can use:

get_post_meta( get_the_ID(), '_regular_price', true);

And for the sale price you can use:

get_post_meta( get_the_ID(), '_sale_price', true);
  • What happens if a plugin has hooked into woocommerce_get_price_html?
    – danyo
    Dec 6, 2017 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.