Skip to content

Instantly share code, notes, and snippets.

@woogist
Created February 27, 2015 08:39
Show Gist options
  • Save woogist/f4384504e24cf67bb0b3 to your computer and use it in GitHub Desktop.
Save woogist/f4384504e24cf67bb0b3 to your computer and use it in GitHub Desktop.
Hides the Ninja Forms add-ons' prices in the cart and checkout pages
/**
* Hides the Ninja Forms add-ons' prices in the cart and checkout pages
*
* @param string $text
* @return string
*/
function wc_nf_hide_price( $text ) {
$text = strip_tags( $text ); // Strip HTML tags <span class="amount"></span>
$pattern ='/\s\([\D]+([\d]+[.?][\d]+)\)/';
/**
* Pattern explained
*
* $pattern = '/\s'; // Any white space/tab before the price
* $pattern .= '\('; // The price parenthesis
* $pattern .= '[\D]+'; // Currency sign
* $pattern .= '([\d]+[.?][\d]+)'; // Decimal amount
* $pattern .= '\)/'; // The price parenthesis
*/
return preg_replace( $pattern, '', $text );
}
add_filter( 'wc_nf_addons_cart_option', 'wc_nf_hide_price' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment