Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdeborba/d7a24b1ea9bb5ee16dde5392bec6e722 to your computer and use it in GitHub Desktop.
Save alexdeborba/d7a24b1ea9bb5ee16dde5392bec6e722 to your computer and use it in GitHub Desktop.
WooCommerce: Hide Price if Value is 0
// Add this code to your child theme's functions.php file
add_filter( 'woocommerce_get_price_html', 'hide_zero_price', 10, 2 );
/**
* Hide price if it is zero
*
* @param string $price The price (HTML formatted).
* @param WC_Product $product The product object.
* @return string
*/
function hide_zero_price( $price, $product ) {
// If the product price is zero or null
if ( 0 == $product->get_price() || '' == $product->get_price() ) {
// Return an empty string instead of the price
return '';
}
// If the price is not zero, return it as is
return $price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment