How to display Woocommerce product price by ID number on a custom page?

I'm trying to display a price of a product in Woocommerce, on a custom page. There is a short code for that, but it gives product price and also adds an "Add to cart button", I don't want the button, i just want to get the price of a specific product by ID.

Is this possible?



<table class="unlockTableBorder">
<h2>פתיחת מכשירי Alcatel כלל עולמי</h2>
<h4>אנא קראו והבינו את תנאי השירות הבאים לפני הזמנת שירות זה:</h4>
	<li>שירות זה תומך בפתיחת מכשירים סלולריים מסוג Alcatel מארה"ב, קנדה ומקסיקו.</li>
	<li>מכשירי CDMA וספקיות שירות CDMA לא נתמכים בידי שירות זה, אנא אל תשתמשו בשירות זה בשביל מכשירים אלו - במידה ותשמשו בשירות זה למכשירי CDMA, אתם תקבלו קוד שלא תוכלו להשתמש בו, ולא תוכלו לקבל החזר כספי! - אנא <a title="פתיחת מכשירי CDMA לכל הרשתות" href="">ראו פתיחת מכשירי CDMA לכל הרשתות בישראל.</a></li>
<h5><strong>זמן הספקה: 1-24 שעות</strong></h5>
<form id="unlock1" class="cart" enctype="multipart/form-data" method="post" name="unlock"><input class="the_imei" style="width: 80%; border-radius: 15px;" name="the_imei" type="text" value="" placeholder="מספר סידורי IMEI של המכשיר (חייג #06#*)" /> <input class="add-to-cart" name="add-to-cart" type="hidden" value="76" /> <button class="unlockButton" type="submit" value="submit">פתח לכל הרשתות בישראל </button></form>*בלחיצה על הפתור, אתם מסכימים ל<a title="תנאי השירות" href="">תנאי השירות</a>.</td>
<script src="" type="text/javascript"></script>


In woocommerce,

Get regular price :

$price = get_post_meta( get_the_ID(), '_regular_price', true);
// $price will return regular price

Get sale price:

$sale = get_post_meta( get_the_ID(), '_sale_price', true);
// $sale will return sale price

If you have the product's ID you can use that to create a product object:

$_product = wc_get_product( $product_id );

Then from the object you can run any of WooCommerce's product methods.


Please review the Codex article on how to write your own shortcode.

Integrating the WooCommerce product data might look something like this:

function so_30165014_price_shortcode_callback( $atts ) {
    $atts = shortcode_atts( array(
        'id' => null,
    ), $atts, 'bartag' );

    $html = '';

    if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
         $_product = wc_get_product( $atts['id'] );
         $html = "price = " . $_product->get_price();
    return $html;
add_shortcode( 'woocommerce_price', 'so_30165014_price_shortcode_callback' );

Your shortcode would then look like [woocommerce_price id="99"]

Other answers work, but

To get the full/default price:


Similar questions

Change product price when product attribute has an additional price (WooCommerce)
For one of my webshops im trying to achieve the following: All of the products in the webshop have variations. For example Product X can be ordered in the color RED but also in the color BLACK. Now im trying to set an additional price in WooCommerce for example the color Black. Color RED - No additional costs Color Black- Additional cost €30 How ca...
Variable product price not showing in listing and details page WooCommerce Price Based on Country
When the product is listed in Product listing page or Product details page, The price not showing.When I click on any variation like color,then only the product price is displayed.If I deactivate the plug-in its all works good. Note: I am using All the products are variable products(color). I surfed on net for this and found something like this *Wo...
Number of Posts - Display number (x of x), if number is less than 4 ( 4 is the post_per_page)
I am showing 4 custom post type posts per category on a parent post type archive page with category rows. I want to show the count of the category posts ($list->found_posts), but I am limiting the displayed posts to a random 4 posts. I have successfully displayed the total number of posts for each category (business_listing is the post type) The...
How can I add below of Woocommerce out of stock product text the Woocommerce product price on a single product
I have a single woocommerce product page where only availability "Out of Stock" message is shown. How can I show a formatted price with currency below that text? I think I need to insert the following but I dont know how This is happening to all simple products. As settings, stock management is disabled. I don't know why price is not displayed. I t...
How to display the regular price and sale price in single product and loop pages?
I had this code in function.php of my child theme to display the regular price and sale price and it was working fine in WooCommerce v2.6.14. But this snippet doesn't work anymore on WooCommerce version 3.2.3. How can I fix that? Here is that code: Thanks to whoever help me out!
Display on shop pages the unit price and the wholesale price on product pages
In Woocommerce, I have set my products with a wholesale price. I'm trying to display the unit price of the products only in shop pages, which should be the wholesale price divided by 6. Any clue?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.