How to display variable prices by default in woocommerce?

The function woocommerce_template_single_price() handling the display of the “normal” price is pluggable, which means it can be overridden putting this into your functions.php:

//override woocommerce function
function woocommerce_template_single_price() {
    global $product;
    if ( ! $product->is_type('variable') ) { 
        woocommerce_get_template( 'single-product/price.php' );
    }
}

This works because in woocommerce-template.php the functions gets initiated like this:

if ( ! function_exists( 'woocommerce_template_single_price' ) ) {
    function woocommerce_template_single_price() {
        woocommerce_get_template( 'single-product/price.php' );
    }
}

As you can see the conditional says if the function not exists, but the function already exists. The one we put into the functions.php will be used, because it is initiated earlier.

To show the the variation price when a single product page with a variable product is loaded, you have to select a default product variation on the product edit page.

Leave a Comment