Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active August 5, 2021 07:52
Show Gist options
  • Save BFTrick/7643587 to your computer and use it in GitHub Desktop.
Save BFTrick/7643587 to your computer and use it in GitHub Desktop.
Disable the WooCommerce variable product "From: $X" price.
<?php
/**
* Plugin Name: WooCommerce Remove Variation "From: $XX" Price
* Plugin URI: https://gist.github.com/BFTrick/7643587
* Description: Disable the WooCommerce variable product "From: $X" price.
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Patrick Rauland
* @since 1.0
*/
function patricks_custom_variation_price( $price, $product ) {
$target_product_types = array(
'variable'
);
if ( in_array ( $product->product_type, $target_product_types ) ) {
// if variable product return and empty string
return '';
}
// return normal price
return $price;
}
add_filter('woocommerce_get_price_html', 'patricks_custom_variation_price', 10, 2);
// that's all folks!
@kenji4861
Copy link

Queenb123 and for other woocommerce 2.2+ users,

Instead of showing up like "$1 - $10", it'll show up these steps will make it show up as "$1"

  1. go to the wordpress administration panel
  2. Click on Plugins
  3. Click Editor
  4. Select plugin to edit : WooCommerce
  5. You can just copy and paste the code on the bottom

function spoofee_custom_variation_price( $price, $product ) {
$target_product_types = array('variable');
if ( in_array ( $product->product_type, $target_product_types ) ) {
return '$'.$product->min_variation_price;
}
return $price;
}
add_filter('woocommerce_get_price_html', 'spoofee_custom_variation_price', 10, 2);

@spyrosvl
Copy link

Do not do what @kenji4861 says. He is doing it the wrong way. @BFTrick provided a plugin. If you do not know how to use the code, it is better to get a dev to implement it for you.

@Bilal951
Copy link

Hi there, PLEASE Help me out, i used kenji4861 his way to add custom code. and now my site is not working...
How can i solve this issue? Please let me know?
Quick response would be appreciated as i am in hurry!

@shadescolour
Copy link

Holy sh*t, it works great... as a plugin!
@Bilal951 if you need help still, let me know and I can fix it for you.

@multiplehats
Copy link

Instead of creating a plugin, you can also add it in your functions.

@dngani
Copy link

dngani commented May 25, 2017

@BFTrick
Nice. Thank you for the code.

@dmgthe2nd
Copy link

What would the code be if I wanted to only show the maximum price? Thanks!

@kameleon1er
Copy link

Hi :-) Thanks for the script, it will help me this is exactly what I need :-) . But I don't know where to place it : in my Child Theme or in Woo ?
Thanks a lot.

@kabbo508
Copy link

You Are a genius man...

@sh00t1ngf1sh
Copy link

Where is the plugin?

@hosseinsnasseri
Copy link

Hi, how can I show the max price instead of the lowest price?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment