Disable Variable Product Price Range on the WooCommerce Single Product Pages Only

I'm looking to hide variable products price range only on the single product pages for the product that is currently being viewed. I do not want the price range to be disabled for all the products listed in the "Related Products" below and any products listed in the widgets in the footer as well.

Everyone of the snippets I've found so far hides the price range for every product listed on the single products page. It also hides the price completely from view from the variable products that have the exact same price for all of them since they do not display below the drop down when selected.

Here is an example of a snippet I've found:

/*
Disable Variable Product Price Range completely:
*/

add_filter( 'woocommerce_variable_sale_price_html', 'my_remove_variation_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'my_remove_variation_price', 10, 2 );

function my_remove_variation_price( $price ) {
  $price = '';
  return $price;
}

Example of price issue below:
enter image description here

Solutions

add_filter( 'woocommerce_variable_sale_price_html', 'ninja_remove_variation_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'ninja_remove_variation_price', 10, 2 );

function ninja_remove_variation_price( $price ) {
if ( is_product() ) {
$price = '';
}
return $price;
}

Let's look on the Visual Hook Guide. The price range is a part of the single product summary. The woocommerce_single_product_summary hook consists of:

 * @hooked woocommerce_template_single_title - 5
 * @hooked woocommerce_template_single_rating - 10
 * @hooked woocommerce_template_single_price - 10
 * @hooked woocommerce_template_single_excerpt - 20
 * @hooked woocommerce_template_single_add_to_cart - 30
 * @hooked woocommerce_template_single_meta - 40
 * @hooked woocommerce_template_single_sharing - 50

And the woocommerce_template_single_price function adds the single-product/price.php template-part.

So we have two ways:

1. Remove this template part for variable products only

add_action( 'woocommerce_before_single_product', 'my_remove_variation_price' );
function my_remove_variation_price() {
  global $product;
  if ( $product->is_type( 'variable' ) ) {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
  }
}

2. Or edit the template part itself

Copy wp-content/plugins/woocommerce/templates/single-product/price.php to wp-content/themes/YOUR_THEME/woocommerce/single-product/price.php and replace this code fragment

  <p class="price"><?php echo $product->get_price_html(); ?></p>

with this one

<?php if ( ! $product->is_type( 'variable' ) ) : ?>
  <p class="price"><?php echo $product->get_price_html(); ?></p>
<?php endif; ?>

This code will remove "From" text without removing the price completely for variable products .

  add_filter( 'woocommerce_variable_price_html','variation_price_min', 9999, 2 );

  function variation_price_min( $price, $product ) {
  $prices = $product->get_variation_prices( true );
  $min_price = current( $prices['price'] );
  $price = sprintf( __( '%1$s', 'woocommerce' ), wc_price( $min_price ) );
  return $price;
   }

Similar questions

Custom Woocommerce variable product price range for more than one active variation
I'm using this script, which I found on the Internet, to remove price range and display only minimum price for variable products in WooCommerce/WordPress in following syntax: From US$ xxxx I'd like the script to do this same thing with exception when variable product has only one variation. There is an automated cron (bash + SQL script) which remov...
Replace Woocommerce product variable price range from custom field values
I want to use a custom field to add price for vendors in variable products. So, I am using the following code to get the maximum and minimum price of custom field of variable product, but it return nothing. Please help me to find how can get the price from custom field for variable products.
Variable product with main price and add variant price to main regular price
Is it possible for a Variable product act as a simple product with a regular price and when a variant is selected then the variant price will be added to the main price?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .