[wordpress] 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?

Thanks.

CODE:

_x000D_
_x000D_
<table class="unlockTableBorder">_x000D_
<tbody>_x000D_
<tr>_x000D_
<td>_x000D_
<h2>????? ?????? Alcatel ??? ?????</h2>_x000D_
<h4>??? ???? ?????? ?? ???? ?????? ????? ???? ????? ????? ??:</h4>_x000D_
<ul>_x000D_
 <li>????? ?? ???? ?????? ??????? ???????? ???? Alcatel ????"?, ???? ???????.</li>_x000D_
 <li>?????? CDMA ??????? ????? CDMA ?? ?????? ???? ????? ??, ??? ?? ?????? ?????? ?? ????? ??????? ??? - ????? ?????? ?????? ?? ??????? CDMA, ??? ????? ??? ??? ????? ?????? ??, ??? ????? ???? ???? ????! - ??? <a title="????? ?????? CDMA ??? ??????" href="http://www.unlocker.co.il/sim-unlock-cdma-mobile-device/">??? ????? ?????? CDMA ??? ?????? ??????.</a></li>_x000D_
</ul>_x000D_
<h5><strong>??? ?????: 1-24 ????</strong></h5>_x000D_
<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="http://www.unlocker.co.il/terms-and-conditions/">???? ??????</a>.</td>_x000D_
</tr>_x000D_
</tbody>_x000D_
</table>_x000D_
<script src="http://www.unlocker.co.il/checkimei1.js" type="text/javascript"></script>
_x000D_
_x000D_
_x000D_

This question is related to wordpress woocommerce product

The answer is


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.

$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();

Update
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:

$product->get_price_html();


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

Examples related to wordpress

#1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’ How to get WooCommerce order details Wordpress plugin install: Could not create directory WooCommerce: Finding the products in database How to get post slug from post in WordPress? How to get featured image of a product in woocommerce Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\wordpress\wp-includes\class-http.php on line 1610 Use .htaccess to redirect HTTP to HTTPs Load More Posts Ajax Button in WordPress How to decode encrypted wordpress admin password?

Examples related to woocommerce

How to get WooCommerce order details WooCommerce: Finding the products in database How to get featured image of a product in woocommerce How to display Woocommerce product price by ID number on a custom page? Get cart item name, quantity all details woocommerce Woocommerce, get current product id How to modify WooCommerce cart, checkout pages (main theme portion) How can I get customer details from an order in WooCommerce? How can I get the order ID in WooCommerce? Woocommerce get products

Examples related to product

How to get WooCommerce order details WooCommerce: Finding the products in database How to display Woocommerce product price by ID number on a custom page? Woocommerce, get current product id Get custom product attributes in Woocommerce Magento Product Attribute Get Value What's the function like sum() but for multiplication? product()?