WooCommerce WordPress

Remove Price Label from WooCommerce Gravity Forms Product Add-Ons

Updated

Written by

Dave Warfel

Reading Time

3 minutes

If you buy something from one of our links, we may earn a commission.

The Gravity Forms Product Add-Ons Extension is a powerful tool to extend a WooCommerce site. One of the great features allows you to create a dropdown list of product add-ons, each which have an associated price assigned to them. This price gets added to the original product price.

By default, the dropdown list includes both the value and the price difference from the currently selected option. What happens if you don’t want to show the price difference? We’ll show you how to remove the price & only display the value.

Gravity Forms – Form Setup

Here’s what the form looks like in Gravity Forms. You have to use the “Option” field type under “Pricing Fields.” Notice we have text for both “Label” and “Price.”

WooCommerce Gravity Forms Add-Ons Option Field Setup

Add Gravity Form To Product

Go to your product edit screen, scroll down to Gravity Forms Product Add-Ons, and select the form you just created.

WooCommerce Gravity Forms - Select Form

Dropdown Displays Price Difference

When you view the product on your website, you’ll see something that looks like this (below). We are going to remove the price differences (ex: +$50.00, -$25.00, etc.) from the dropdown.

WooCommerce Gravity Forms Price Label
“fieldLabel” is highlighted in green. “priceLabel” is highlighted in red. Your values might be different, depending on how you setup your options field in the form.

How to Remove priceLabel from Dropdown

We are going to use a filter provided by Gravity Forms called gform_format_option_label. If you are using a child theme, this code should be placed there. I recommend putting this code in your footer.php file, but you could optionally include it in the <head> section of header.php, or your own linked JavaScript file.

I’m placing it in footer.php:

  • because it doesn’t need to load before the page content, so this will help speed up the page load
  • so I can use an if statement to only include it on single product pages (the only pages that ever display the form)

Here’s what the code looks like. Place this immediately before the call to <?php wp_footer(); ?>:

<?php if ( is_singular('product') ) { // only single product pages ?>
	<script type="text/javascript">
	function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {
	// Disable option pricing. Simply return the field label.
	// This removes the "+$25.00" or "-$100.00" from the dropdown.
		return fieldLabel;
	}
	</script>
<?php } // end if, single product pages ?>

This will remove the priceLabel (+$50.00) from the dropdown menu, and only display the fieldLabel. The above code will do this for ALL fields on your site.

Gravity Forms - How to find formId
How to find formId

Remove priceLabel for a specific form

To do this, use the formId parameter:

<?php if ( is_singular('product') ) { // only single product pages ?>
	<script type="text/javascript">
	function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {
	// Only for form with ID of 1
	if (formId == 1)
	// Disable option pricing. Simply return the field label.
	// This removes the "+$25.00" or "-$100.00" from the dropdown.
		return fieldLabel;
	}
	</script>
<?php } // end if, single product pages ?>
Gravity Forms - How to find fieldId
How to find fieldId

Remove priceLabel for a specific field

To do this, use the fieldId parameter:

<?php if ( is_singular('product') ) { // only single product pages ?>
	<script type="text/javascript">
	function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {
	// Only for field with ID of 5
	if (fieldId == 5)
	// Disable option pricing. Simply return the field label.
	// This removes the "+$25.00" or "-$100.00" from the dropdown.
		return fieldLabel;
	}
	</script>
<?php } // end if, single product pages ?>

Remove price label from WooCommerce email notifications

The ability to remove the price label from email notifications was asked about several times in the comments, and Yhlas Sovbetov was generous enough to write up some code to solve this. Please see his comment below.

Dave Warfel

LinkedIn  •  X (Twitter)Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

55 responses to “Remove Price Label from WooCommerce Gravity Forms Product Add-Ons”

  1. James Avatar

    This is some great info, I am trying to figure out something similar and wondering if you might know the answer, I want to keep the price value on the drop downs so people can see selection price differences, but I do not want to show the price of each value in the cart like right now it will show “Part Name” (“price”) I don’t want that price at the end of each line in the cart, just a total, or even the (+”price”) or (-“price”) would be fine as I have a built in default item price which is not shown if the customer adds up prices of options it will make no sense to them.

    1. Dave Warfel Avatar

      James, you might be able to figure it out using the options on this Gravity Forms help page.

      fullLabel – Will display everything
      fieldLabel – Will just show the label name (no pricing info)
      priceLabel – Will just show the pricing difference (+$5.00)
      price – Will just show the price that you set for that particular product option

      In the above code, you’d change this line:

      return fieldLabel;

      to something like this:

      return fieldLabel + " (" + price + ")";

      That should show: Part Name ($10.00) in the dropdown, if that particular part costs $10.00.

      Respond to my email if that doesn’t work, and I’ll try to help you out.

    2. James Avatar
      James

      I replied to your email.

      problem is not within the drop down list, the drop down displays fine, it shows the adjusted price if they change the item which is fine.

      It’s within the data it sends to the cart or how the cart displays it.
      Right now default is “Item” (“price”) I don’t want the price to show beside each item in the cart if you know what I mean, or have if show just the variation (not the full option value) of the selections they made if not the default options.

      I hope that made more sense, anyway I sent an email with pictures attached.

    3. Dave Warfel Avatar

      I understand.

      Unfortunately, I’m not sure how to change how the label & price are displayed in the cart. The above code only works for the dropdown on single product pages.

      You could write a little custom PHP, using the preg_replace function, and use a regular expression. I don’t understand them well enough to give you any example code, but the idea would be:

      Find this -> everything that starts with “($” and ends with “)”. Use the global selector (*) in the middle.
      Replace with -> “” (an empty string)

      A PHP expert would be able to easily write that code.

  2. James Avatar
    James

    Thanks for trying, I will see if I can get someone to try that.

    1. Max Avatar

      Hi James,

      did you solve your problem with the price label in the cart? If yes, how did you do that? I have the same problem and I am not able to write a php file myself, neighter do I know where to place that file in the woocommerce structure ;)

    2. James Avatar
      James

      I reached out to the woocommerce support for the gravity forms extension and they told me this.

      “I’ve been talking to a WC developer and the Gravity Forms Add On developer and right now there doesn’t appear to be a way to do this. We might be able to come up with something for WooCommerce 2.2 which is 6+ months out but we change anything until then.

      Sorry for the bad news but that’s all we can do at this point.”

      “We’ve added this to our 2.2 milestone on GitHub.
      https://github.com/woothemes/woocommerce/issues/4325

      You can follow the progress there.”

      unfortunately I had to rework my cart system by adding in a base price and having all options be +/- on the base price in order to make it work right in the cart screen. Which was a pain as I had to rework each item separately even though many share the same price info.

  3. Hale Avatar
    Hale

    It has been resolved in version 2.7.1.
    Just join WooGang Club and get this and many more extensions.

    1. Dave Warfel Avatar

      Hale,

      This looks to me like you’re just trying to promote your theme/plugin club, and that’s not what these comments are for.

      First, there really isn’t any issue here that needs resolving. It’s just a preference on how you want information displayed. I don’t think there’s such a thing as “resolving” it.

      Second, per the offical changelog for the plugin (here), there is absolutely no mention of this in version 2.7.1.

      Third, for anyone reading this, we recommend you purchase the official extension from it’s developer, WooThemes, using this link.

  4. Melle Avatar
    Melle

    Does anyone know how I would apply this to hide the price from the actual cart page as well? It’s working for the products, but in the cart all the components are still showing with the price. Would REALLY appreciate any help.

  5. Russ Powers Avatar

    Hey, so I’ve been able to truncate the priceLabel from the product, mini-cart widget, cart page, and checkout/thank you page. However, I haven’t figured out how to truncate the priceLabel in the confirmation emails. Right now, I only have two products with three variations each that require the priceLabel to be truncated. So I think an if statement may be required.

  6. Craig Grella Avatar

    I have a site that uses custom code to replace the add-to-cart text with donate now.
    But when I use gravity add on to add some custom checkout stuff, it replaces the custom code i added with the standard add to cart text again. Any ideas on how to change the add to cart text when using gravity add on?

    1. Peter Luit Avatar

      Same question here. I simpy want to hide some GF field from displaying in the cart, but also in het e-mail to the customer. Any ideas?

      Peter

  7. christopher Avatar
    christopher

    Hey man, this’ working nicely! Thank you :)

    Would you be able to tell me how to transpose this into a function so I can put it into the functions.php? I have tried a few varients, but it keeps whitescreening…

    1. Dave Warfel Avatar

      Christopher,

      This article might help you out: http://stackoverflow.com/questions/2800778/adding-text-before-footer-in-wordpress

      1. You’ll create a function. Give it any name you want.
      2. You’ll mimic the code used above, only be sure to use echo statements to output the code.
      3. After the function is created, you’ll use add_action('wp_footer', 'your_function');. This will insert that function into the footer of your page.

      Example: (not tested, but it will go something like this)

      add_action('wp_footer', 'woocom_price_label');
      
      function woocom_price_label() {
         if ( is_singular('product') ) {
      	$content = '<script type="text/javascript">';
      	$content .= 'function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {';
      	$content .= 'return fieldLabel';
      	$content .= '}';
      	$content .= '</script>';
         }
         echo $content;
      }
    2. Christopher Avatar
      Christopher

      Thanks so much man! Many many thanks :) Lots of them in fact ;)

  8. goudjil Avatar

    Hi,

    How i could remove 1 or more gravity form product add-ons fields (label and price) on all woocommerce cart pages using functions.php (on child theme). And how remove the same things on the order email sent to client.

    Please give me a response as soon as possible. it’s urgent. Thanks.

    1. goudjil Avatar
      goudjil

      There is nobody have a response for my question ????

    2. Dave Warfel Avatar

      Hi goudjil,

      I’m not sure how to do what you’re asking, and unfortunately, I don’t have time in the next few days to investigate further.

      This is something we maintain in our spare time, and provide help when we can, but it is not our main job. We do the best we can to answer comments, but sometimes we can’t get to them all.

      Best of luck finding an answer.

    3. goudjil Avatar
      goudjil

      Thanks

  9. Redjek Avatar
    Redjek

    good afternoon.
    Tell me how to remove the $ sign in the price. And replace it with another sign

  10. redjek Avatar
    redjek

    Thanks for the quick reply. But it’s not.
    Here’s a look Pictures
    1 http://joxi.ru/vn2YzyobIkQRA6
    2 http://joxi.ru/LQ2KxWoluOo6Aj
    Here’s how to change it on the first picture
    Methods tried, did not work

    1. Christopher Avatar
      Christopher

      You can also change your currency the dirty way: have a look at currency.php in the gravityforms plugin.
      You will find the list of currencies.
      Copy one as a template, change the symbol and upload to your server.
      Then select it in the general settings for GF.

      Bare in mind, I say this’ dirty, because the changes will be lost when you upgrade GF…

  11. Mike Avatar
    Mike

    Sorry for bumping an old topic, but i have a similar question. I like to have the woocommerce pricing to be shown, but instead of gravity forms standard total, i like to have the pricing of woocommerce to change while customers choose an option.

    Is there any solution for this?

    thank you

    1. Dave Warfel Avatar

      Never too late to bump a topic, Mike.

      Is it a variable product? And where is the price being shown (that you’re trying to manipulate it)?

      I setup a test variable product with 3 options, each with a different price. On the product page, when I choose different options, you’ll see the price change automatically: http://cl.ly/ZMiZ

      If you can provide more specifics, I might be able to dig a little further.

    2. Mike Avatar
      Mike

      Hi Dave,
      thank you for the fast respawn!
      Its something like what you have shown, but a little bit different.
      It is indeed a variable product, but i use gravity forms drop down instead of the standard variable product of woocommerce, because there are a lot of variations. So i use simple product and set the pricing, that pricing lable is what i like to change if i choose some variables( like in youre example where you have put 10-30 dollars, beneath the short product details). I know there is a total in gravity form but i like the big pricinglable of the product/theme better for the website.

      I like to show you the product of my website, so you can see it for yourself, but i am not sure if i am allowed to post any links.

      Thank you

    3. Dave Warfel Avatar

      Mike, please post a link here. I’ll take a look.

    4. Mike Avatar
      Mike

      http://oculucida.nl/?product=airoptix-color
      Its dutch, the dropdown at linkeroog rechteroog (left eye and right eye). Those are the options.

  12. mike Avatar
    mike

    I guess there are no answers to my question, thanks anyway

    1. Dave Warfel Avatar

      Hey Mike. Sorry I haven’t gotten back to you yet. I still plan on taking a look, things have just been really busy for me the past few days.

  13. Johannes Avatar

    Big thanks to you guys, it works like a charm!

  14. Andy Avatar

    Hi, Have been looking trough this thread, and the removing the + 1 pricing worked a treat – however I still have a random word ‘price’ above my product variables – how would I hide this?

    1. Dave Warfel Avatar

      Andy — can you send me a screenshot? Is it appearing on your product pages or your cart?

      Unfortunately, I don’t know of any way to change the output of the cart page (http://cl.ly/dBcw).

  15. Cantin Avatar
    Cantin

    You had informed us about to change Option pricing in dropdown
    but issue in still unresolved about cart and emails?

    I don’t want to show option pricing in woocommerce cart and in notification email

    Please help

  16. Cantin Avatar
    Cantin

    I had consulted with a developer from mksofttech.com and he helped me to remove dropdown price from WooCommerce cart.

    Open common.php file in > wp-content\plugins\gravityforms\common.php

    Find: (Line 2153)

    if ( ! empty( $price ) ) {
    	return "$val (" . self::to_money( $price, $currency ) . ')';
    }

    And replace it with:

    if ( ! empty( $price ) ) {
    	//return "$val (" . self::to_money( $price, $currency ) . ')';
    	return "$val";
    }

    Save and you’re done.

    Dropdown price from Gravity Forms will be removed from WooCommerce cart and checkout page too.

    Thanks.

    1. Dave Warfel Avatar

      Thanks for the code snippet, Cantin.

      Be very careful updating plugin files, as they could change with future updates. As you probably know being a Gravity Forms user, they update their plugin frequently. If they make any changes to the common.php file, and you run an automatic update, you’ll lose this change. Just keep that in mind.

      I wish I knew of a better way, but unfortunately, I don’t.

    2. Cantin Avatar
      Cantin

      Thanks for your response. I will make changes on child theme to avoid reversal of changes at the time of update.

      Secondly, I am now stuck in another problem.

      I want to show dropdown price in Cart but now I don’t want that price to pass or show in Woocommerce order email.

      Do you know how to do that?

    3. Dave Warfel Avatar

      Try this:

      1. Start by going to WooCommerce > Settings > Emails > Completed Order
      2. Scroll down and click the “Copy file to theme” button (screenshot)
      3. Comment out this line: <?php echo $order->email_order_items_table( true, false, true ); ?>
      4. Copy the code that WooCommerce uses for email_order_items_table here, and turn it into your own function. Copy everything from foreach to endforeach.
      5. Echo that new function in place of the email_order_items_table

      This article might help you as well.

  17. Cantin Avatar
    Cantin

    Can you guide me one thing, This file is not working in child theme

    My-Child-Theme\gravityforms\common.php

    Child theme is already activated my gravity form files not working in childtheme. Any solution?

    1. Dave Warfel Avatar

      Hi Cantin — I’ve never customized Gravity Forms by using a file in a child theme. Can you send me a link to where you saw this solution?

      I couldn’t find any documentation that mentioned using a /gravityforms/ folder inside of a child theme as a way to customize Gravity Forms. I know you can use some of the many hooks & filters that GF provides, but typically you’d place those in a custom plugin, or the functions.php file of your child theme.

      The solution that a previous developer helped you with was applied directly to the common.php file in the plugin, which I would NOT recommend, because as soon as you update the plugin, that code change will be lost. Copying that common.php file to your child theme will not work.

  18. Ahmed Nabil Avatar
    Ahmed Nabil

    hello i’m trying to remove some fields created by the form after submitted to the woocommerce admin orders page

    for example the form created on the order page a custom field/metadata called “Color”

    i want to remove it from the admin order page along with its value.

    1. Dave Warfel Avatar

      Ahmed — Sorry, but I’m not sure how to do that. I’m also confused as to WHY you’d want to do that.

      If you’re asking a customer to choose a color, and then collecting that information during their order process, why would you want to hide that info in the admin? Wouldn’t you want to know what color they chose?

      The only solution I could offer up would be to use CSS to display:none; the color value in an admin-only stylesheet. But that’s a messy solution.

  19. Vlad_N Avatar
    Vlad_N

    Hi there,
    thank you for this. However I stile have all custom fields shown on my email template sent to customer and received by admin. How can I remove some of them. For example I have:
    1. Color variations
    2. Size variations
    3. weight Variations
    4. Prices

    On my email sent to customer I want to see only chosen color variation and Size.

    Thank you!

    1. Dave Warfel Avatar

      Vlad — You’ll need to edit the default email template. If you go to WooCommerce > Settings > Emails, you’ll see “Completed Order.” Click on it. This is likely the email you are wanting to change.

      There are instructions on the page that explain you need to copy the file & place it in your active theme to override it.

      If that proves somewhat difficult, there is an extension you can purchase that makes it easier to customize emails. — https://docs.woocommerce.com/document/woocommerce-email-customizer/

  20. Karim Avatar
    Karim

    Hi,

    All seems like great help here. Thanks :-)

    I’m looking for some guidance (or perhaps someone to code), a couple of changes to the Gravity Woo Add On.

    I want the form to display AFTER selecting add to cart, but the item should not add to cart until after the form is complete.

    It’s for medication, so we need to collect information about the user, and have the product page in a template file. . . hence displaying the forms in this template doesn’t really work.

    Secondly the product variations prices don’t update when the add on is activated. . .it seems to default to the add on pricing which I don’t want to use. Is there anyway to remove the price info from the gravity form addon, and just leave the woo commerce price info in place, which also updates via ajax?

    Many Thanks in advance for any assistance!

    1. Dave Warfel Avatar

      Hi Karim,

      I wish I had a better answer, but unfortunately, I cannot help you with either of your requests. Fingers crossed someone in this thread might respond & be able to help. If I should happen to stumble upon anything that might help, I’ll let you know. Best of luck.

  21. Anil Sharma Avatar
    Anil Sharma

    I am using same plugin. In my products I am using Product part number in option value and Part name in option name but when I got a order email I receive option name. I want to get in order email part number (option value )not option Name.
    How can I do that.

    Here is screenshot link
    http://www.tiikoni.com/tis/view/?id=5e28f85
    My option field is based on conditions.
    please help me.

    Thanks in Advance.

    1. Anil Sharma Avatar
      Anil Sharma

      There is no one have a response for my queries ????

    2. Dave Warfel Avatar

      Hi Anil — Sorry, but I’m not sure how to do that. Best of luck in searching for an answer.

  22. Anil Sharma Avatar
    Anil Sharma

    Hi Dave,
    Thanks for your nice article on Remove Price Label from WooCommerce Gravity Forms Product Add-Ons. I had searched many articles on this but I found in your article best help. hopefully If I will found any solution I will put that in comment section.

  23. JS Avatar
    JS

    I was wondering if you could help!?
    the Order Total: in the metadata/description of the product shows the variation total and this is creating much confusion with several of our customers. I was able to use CSS to hide it in the cart but it remains on the invoice.

    i.e.
    4A Alpha Panel Diffusor / Absorber (4″)
    Choose a size: 23.75″ x 23.75″ (4 per box $79 each)
    Select diffusion pattern 23.75″ x 23.75″: Two-Dimensional scattering (+$20 each) ($80.00)
    Alpha Plate Options: Blonde Wood veneer
    Back Side Options 23.75″ x 23.75″: White Muslin backing for mounting against wall
    Select 23.75″x23.75″ Fabric Color: Black – Standard
    Total: $80.00

    the total is just the total of the add ons, the amount above the base price of the item.

    Please let me know if you can help me remove that total from displaying everywhere.

    1. Dave Warfel Avatar

      Hi JS. Unfortunately, I’m not sure how to achieve that. Sorry. Wish I could be of more help.

  24. Yhlas Sovbetov Avatar
    Yhlas Sovbetov

    Guys, I can help you to remove price tags from email notification in woocommerce. Just follow me:
    1) open: wc-template-functions.php
    add following code there:

    if ( ! function_exists( 'wc_custom_display_item_meta' ) ) {
    	function wc_custom_display_item_meta( $item, $args = array() ) {
    		$strings = array();
    		$html    = '';
    		$args    = wp_parse_args( $args, array(
    			'before'    => '',
    			'after'		=> '',
    			'separator'	=> '',
    			'echo'		=> true,
    			'autop'		=> false,
    		) );
    		
    		$array_field_names = array('Product name  1', 'Product name 2', 'Product name 3');
    		
    		foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
    			$meta_label = $meta->display_key;
    			$meta_value = $meta->display_value;
    			$meta_value_only = explode('(', $meta_value)[0];
    			if (in_array($meta_label, $array_field_names)) {
    				$value = $args['autop'] ? wp_kses_post( wpautop( make_clickable( $meta_value_only ) ) ) : wp_kses_post( make_clickable( $meta_value_only ) );
    				$strings[] = '' . wp_kses_post( $meta_label ) . ': ' . $value;
    			}
    		}
    
    		if ( $strings ) {
    			$html = $args['before'] . implode( $args['separator'], $strings ) . $args['after'];
    		}
    
    		$html = apply_filters( 'woocommerce_display_item_meta', $html, $item, $args );
    
    		if ( $args['echo'] ) {
    			echo $html;
    		} else {
    			return $html;
    		}
    	}
    }

    Note that you should write which field name you want to display at email notification table in array in above code: $array_field_names = array(‘Product name 1’, ‘Product name 2’, ‘Product name 3’);

    2) open email-order-items.php
    change
    wc_display_item_meta( $item );
    with
    wc_custom_display_item_meta( $item );

    That is it :) It will only display Product name and it value without price tags.

    1. Johannes Avatar
      Johannes

      I want to filter out unwanted order item meta data from Woocommerce email notifications especially gravity forms field labels. With gravityforms and gravity forms product add on it is possible that any customer can engrave a product. licence plates for cars etc.
      e.g. eins:M zwei:TU drei:2019 .
      i want to hide the field labels (eins, zwei, drei) and the double points : in the email-notifications.

Leave a Comment