# Product Price Shortcode

> Adds a [wpide_product_price id="123"] shortcode that prints the current price of any product, including sale formatting, inside posts and pages.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shortcode, price
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-product-price-shortcode/

## Code

```php
add_shortcode( 'wpide_product_price', function ( $atts ) {
    $atts = shortcode_atts( array( 'id' => 0 ), $atts, 'wpide_product_price' );

    $id      = absint( $atts['id'] ) ? absint( $atts['id'] ) : get_the_ID();
    $product = $id ? wc_get_product( $id ) : false;

    if ( ! $product ) {
        return '';
    }

    return '<span class="wpide-product-price">' . wp_kses_post( $product->get_price_html() ) . '</span>';
} );
```

## Notes

Use the product ID from the Products list. On a product page the id can be omitted.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Product Price Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
