Remove Qty from Cart Description

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

Default description: Product Name A: Qty: 1, Price: $0.00

Quantity removed: Product Name A: Price: $0.00

Instructions

Code

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

<?php
/**
 * Gravity Forms // WC GF Product Add-ons // Remove Qty from Cart Description
 * https://gravitywiz.com/
 *
 * Instruction Video: https://www.loom.com/share/00c1d1ec36bb4f1f93fa2d3f823ee264
 *
 * Add "wcgfpa-remove-qty" to your field's CSS Class Name setting and this snippet will automatically remove the
 * quantity from the product's description in the cart.
 *
 * Default description:
 * Product Name A: Qty: 1, Price: $0.00
 *
 * Quantity removed:
 * Product Name A: Price: $0.00
 */
add_filter( 'woocommerce_gforms_field_display_text', function( $display_text, $display_value, $field ) {
	if ( strpos( $field->cssClass, 'wcgfpa-remove-qty' ) !== false ) {
		preg_match_all( '/Qty: [0-9]+, /', $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.