Get woocommerce product price by id
i make one shortcode for get product title, image and price. i am getting all title, link and image properly but not getting price. but problem is
$post_id = $atts['id'];
$title = get_the_title($post_id);
$link = get_the_permalink($post_id);
$price = get_the_price($post_id);
$image = get_the_post_thumbnail($post_id, 'thumbnail');
$data ='<div class="releated-products wow fadeInUp"><a href="'.$link.'">'.$image.'<h5>'.$title.'</h5><h6>'.$price.'</h6></a></div>';
$price = get_the_price($post_id); i guess this function not correct
any idea how to get price now.
You can create a product object using the following function:
$product = wc_get_product( $post_id );
And after that you will be able to access to all product's data. All available methods can be found here, but the ones you need are:
WooCommerce product price visibility: add price back only for a specific category
The website I am working on requires you to be logged in to see prices and I've been using a plugin to do this. However, I was just thrown a curve ball and told that one specific category on the website must have prices shown all the time, regardless if the user is logged in or not. It looks like the plugin uses and to remove the prices. And this i...
If sale price is equal to zero show only regular product price in Woocommerce
I run my woocommerce product updates via xml feed upload. However when a product is not on sale the sale price is set to 0 and some blank. I want a situation whereby when a product has a sale price of 0 it should only show regular price. I did get it to work with this code However woocommerce then just displays this below, instead of just regular p...
Product price suffix with a price calculation based on weight in WooCommerce
I am using "https://stackoverflow.com/questions/53435276/custom-product-price-suffix-on-based-on-product-categories-in-woocommerce/53438506#53438506" answer thread that allow to adjust my pricing display with a prefix this way: But what I would actually like is to make the $price output what the price of the item is divided by the weight ...
WooCommerce - Show Regular and Sale Price for The Product Variation which has Flat Price
The scenario is Simple product, Variable product are woocommerce's two different product types. What I am trying to achieve is, there are some products which have over 50+ variations which have a different sale and regular prices. A price range for that product is fare. But there are also products which's variations have same regular and sale price...