Created
June 14, 2023 18:49
-
-
Save alexdeborba/d7a24b1ea9bb5ee16dde5392bec6e722 to your computer and use it in GitHub Desktop.
WooCommerce: Hide Price if Value is 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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