I realize this should be simple for most coders but I am not a coder!
I want to display product price including Currency symbol somewhere on my page/text.
I have done this before but have totally forgotten how to do it! I have copied the code below but am unsure where to place it, also do I replace post_id with my product ID? any help from you guys appreciated
$product = wc_get_product( $post_id );
$product->get_regular_price();
$product->get_sale_price();
$product->get_price();
3
Answers
You can display the products with prices anywhere in your site using this code
'product_cat'
=> is what your product category should be shown or else remove that if you need to display all the products<?php echo '€'. $product->get_regular_price();?>
is used to display the products price and you can also change the price symbol as per your need.You can do that simply by.
where
$_product
iswc_get_product( $product_id )
.This ensures that it is compatible for future updates of woocommerce and extensions.
You can use the below function for your requirement.
So this is a shortcode. You can add
[woo_product_price id="your_product_id"]
to show the price of a particular product in any page. All you have to do is to add the above mentioned shortcode to the page and provide an ID.This shortcode shows price of product including the currency. As an advantage, if the product is on sale, the sale price will also be shown.
See the image to get an idea on how it look.