Search code examples
phpwordpresswoocommerceproduct

Add Woocommerce product price (+ currency) with add to cart in a page


I've set up a add-to-cart button of a woocommerce product on my landing page. Is there a way to also show the price of the product on that page (or any page)? The class of the woocommerce price is called "woocommerce-price-amount".

Of course I could just use a text field and "type" the price amount myself. But I'd have the problem with the currency. The beauty of the woocommerce price amount is, that it would show the price in euro or dollar (depending on your geo-location for example)

Is there a shortcode or another way to solve this or is this really restricted to use on individual product pages?


Solution

  • You can use existing Woocommerce Add to Cart Shortcode like that displays the formatted product price with the currency:

    [add_to_cart id='123' quantity='1' class='custom' style='']
    

    or in any php page or code using WordPress do_shortcode() function:

    echo do_shortcode("[add_to_cart id='123' quantity='1' class='custom' style='']");
    

    Or like "Woocommerce Add to cart link Ajax enabled in other post or pages" you can make your own custom shortcode.