Reputation: 1190
I am trying to fetch the product id and price in functions.php, so i can use that price in my hooks right now i am using this code and
i am getting
ID=0(id is like 99, 1733 etc)
price = Free(but default price is something else)
$product = new WC_Product( get_the_ID()) ;
echo $prices = $product->get_price_html();
echo $price1= $product->id;
Any help will be much appreciated!
Upvotes: 2
Views: 16813
Reputation: 1299
Try this code -
<?php
global $product;
$product_id=$product->id;
echo $product_id;
$price=$product->get_price_html();
echo $price; ?>
Upvotes: 3