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

Cover Image for How to display Woocommerce product price by ID number on a custom page?
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

How to Display Woocommerce Product Price by ID Number on a Custom Page

Are you looking to display the price of a specific product on a custom page in Woocommerce? Look no further! In this blog post, we'll explore easy solutions to this common problem.

The Dilemma

Recently, a reader reached out to us with a question. They wanted to display the price of a product in Woocommerce on a custom page. However, the existing shortcode not only displayed the price but also added an "Add to Cart" button. The reader only wanted the price, no buttons.

The Solution

Fortunately, it is possible to achieve this desired result. Here's how you can display the price of a specific product by its ID number on a custom page:

  1. First, you will need the ID number of the product you want to display the price for. You can find this ID number by navigating to the "Products" section in your Woocommerce dashboard and hovering over the desired product. Look at the URL in your browser's address bar, and you should see a number following "post=" - this is the ID number.

  2. Once you have the ID number, open the custom page where you want to display the price and add the following code snippet:

<?php
$product_id = YOUR_PRODUCT_ID;
$product = wc_get_product( $product_id );
$price = $product->get_price();

echo "Price: $" . $price;
?>
  1. Replace YOUR_PRODUCT_ID with the actual ID number of the product you want to display. This code will retrieve the price of the specified product and store it in the $price variable.

  2. Afterwards, the price will be displayed on the custom page using the echo statement. Feel free to customize the output format to better suit your needs.

That's it! You have successfully displayed the price of a specific product on your custom page, without any unwanted buttons.

Have Fun Customizing!

Now that you know how to display the price of a Woocommerce product by its ID number, the possibilities for customization are endless! You can incorporate this feature into your website's design, create product comparison tables, or even use it for dynamic pricing.

If you have any other questions or need further assistance, don't hesitate to reach out. We're always here to help!

Happy customizing! 💪😎🎉


Was this blog post helpful? Did you encounter any issues or have additional questions? Comment below and let's continue the conversation!


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello