Remove Price from Cart Description

Add “wcgfpa-remove-price” to your field’s CSS Class Name setting and this snippet will automatically remove the price from the product’s description in the cart.

Default description: Product Name B: Second Choice ($25.00)

Price removed: Product Name B: Second Choice

Instructions

Code

Filename: wcgfpa-remove-price-from-cart-description.php

<?php
/**
 * Gravity Forms // WC GF Product Add-ons // Remove Price from Cart Description
 * https://gravitywiz.com/
 *
 * Instruction Video: https://www.loom.com/share/c9ac3ed9e85443e9888b0bfc99889044
 *
 * Add "wcgfpa-remove-price" to your field's CSS Class Name setting and this snippet will automatically remove the
 * price from the product's description in the cart.
 *
 * Default description:
 * Product Name B: Second Choice ($25.00)
 *
 * Price removed:
 * Product Name B: Second Choice
 */
add_filter( 'woocommerce_gforms_field_display_text', function( $display_text, $display_value, $field ) {
	if ( strpos( $field->cssClass, 'wcgfpa-remove-price' ) !== false ) {
		preg_match_all( '/\(.+?\)/', $display_text, $matches, PREG_SET_ORDER );
		$match        = array_pop( $matches );
		$display_text = str_replace( $match[0], '', $display_text );
	}
	return $display_text;
}, 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.