Skip to content

Instantly share code, notes, and snippets.

@woogist
Created May 4, 2015 08:00
Show Gist options
  • Save woogist/989d0d4c8ea9eafc2f2b to your computer and use it in GitHub Desktop.
Save woogist/989d0d4c8ea9eafc2f2b to your computer and use it in GitHub Desktop.
/**
* 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{0,2}\d{0,3};)\s?\d+([\.,]\d+)?\s?[\D+]?\)$/";
/**
* Pattern explained
*
* $pattern = '/\s'; // Any white space/tab before the price
* $pattern .= '\('; // The price parenthesis
* $pattern .= '(\D{0,2}\d{0,3};)';\s? // Currency sign on the left
* $pattern .= '\d+([\.,]\d+)?'; // Decimal amount
* $pattern .= '\s?[\D+]?' //Currency sign on the right
* $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