Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created June 26, 2025 09:58
Show Gist options
  • Select an option

  • Save shameemreza/4add4af40cb73104f18e77eea54e132d to your computer and use it in GitHub Desktop.

Select an option

Save shameemreza/4add4af40cb73104f18e77eea54e132d to your computer and use it in GitHub Desktop.
Hides the product price on the frontend if it's set to zero in WooCommerce.
/**
* Hide price if it's set to zero
*/
function a8c_hide_zero_prices( $price, $product ) {
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
$price = '';
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'a8c_hide_zero_prices', 10, 2 );
@shameemreza
Copy link
Author

/**
 * Hide the Add to Cart button for products with zero price
 */
function a8c_hide_add_to_cart_zero_price( $purchasable, $product ) {
     if ( '' === $product->get_price() || 0 == $product->get_price() ) {
          return false;
     }
     return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'a8c_hide_add_to_cart_zero_price', 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment