How to print product price from woocomerce


#1

Hi,

I my having troubles trying to print woo commerce price in my template files for my new them.

What I am trying to do is to print single product price in a front slider carousel located in header.php.

<?php global $product; ?> <?php query_posts('post_type=product&meta_key=slider&meta_value=1'); ?>
	<?php if (have_posts()) : ?>	<br />
  <ul id="mycarousel" class="jcarousel-skin-header-slider"><br />
		<?php while (have_posts()) : the_post(); ?>	<br />
		<li><br />
			<?php the_post_thumbnail('slider'); ?><br />
			<div class="description"><br />
				<span class='price'><?php echo $product->get_price_html(); ?></span><br />
			</div><br />
		</li><br />
		<?php endwhile; ?><br />
  </ul>
<?php endif ?>
Fatal error : Call to a member function get_price_html() on a non-object in D:\xampp\htdocs\cooker\wp-content\themes\cooker\header.php on line 130 I noticed that I cannot get the product class if I use this piece of code before wp_footer().

#2

Ok I solve it.

Hope it will help to someone else.

global $woocommerce;

<?php $product = new WC_Product(the_ID()); ?> <?php echo $product->get_price_html(); ?>

#3

Double post Sorry


#4
Design_Mania said

Ok I solve it.

Hope it will help to someone else.

global $woocommerce;

<?php $product = new WC_Product(the_ID()); ?> <?php echo $product->get_price_html(); ?>

You just saved my time, very appreciate this!