How to get price of a product in WooCommerce in a different page

Today i need it to get a price of a product in a different page from WooCommerce pages.

This is quite an easy task to do. I have created a function called get_price_product that helped me do that.

function get_price_product($id){
       $_price = wc_get_product( $id );
       if($_price->get_sale_price()){  // if sale price is active return sale price
            return $_price->get_sale_price();
       }else{
            return $_price->get_regular_price();
       }
}

I added this function in functions.php on my theme folder. This is a great addition to get prices from a different page to any page in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

tutorials