Skip to content

Instantly share code, notes, and snippets.

@harishankerr
Last active August 12, 2016 11:27
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 harishankerr/eb830b271176c1043b9ca861a695f863 to your computer and use it in GitHub Desktop.
Save harishankerr/eb830b271176c1043b9ca861a695f863 to your computer and use it in GitHub Desktop.
Modify the display of free price in cart
<?php // only copy if needed
/**
* Change cart price display for free products
*
* @param string $price_html the price display html
* @param \WC_Product
* @return string - updated pricing html
*/
function sv_wc_free_cart_price( $price_html, $product ) {
if ( 0 === (int) $product->get_price() ) {
$price_html = 'Free';
}
return $price_html;
}
add_filter( 'woocommerce_get_price_html', 'sv_wc_free_cart_price', 10, 2 );
add_filter( 'woocommerce_cart_product_price', 'sv_wc_free_cart_price', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment