How to output low price in WooCommerce?

Pretty simple what I am trying to do here, I’m just stuck since WooCommerce is new to me, and I’m still learning PHP as we speak.

I’m using the latest version of WooCommerce and WordPress with a custom theme. In one of the themes templates I want to output the price of a product.

Read More

The issue is, this product has variations, so instead of outputting the price as “$154–$592” (which is the standard WooCommerce price output for products with variations) I would rather output it as “Starts at: $154“.

In other words, I only want to echo the low price, with the words “Starts at:” preceding it,

Does this make sense?

Related posts

1 comment

  1. Solve this one myself! Here’s how you do it:

    Add this code below to your themes function.php file…

    // Display only low price for variable WooCommerce products
    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
    
    function custom_variation_price( $price, $product ) {
    
    $price = 'Starts at: ';
    
    
    $price .= woocommerce_price($product->get_price());
    
    return $price;
    }
    

    Now add this code to your template where you want to display the price…

    <?php echo $product->get_price_html(); ?>
    

    Works like a charm for me!

Comments are closed.