1
votes

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

3

3 Answers

3
votes

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; ?>
0
votes
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;
}
0
votes

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;
   }