Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created April 5, 2017 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudiosanches/15a7f72970ba047710a17126438f0e88 to your computer and use it in GitHub Desktop.
Save claudiosanches/15a7f72970ba047710a17126438f0e88 to your computer and use it in GitHub Desktop.
WooCommerce - Restore "Free!" for free simple products on WooCommerce 3.0.
<?php
/**
* Restore single product "Free!" on WooCommerce 3.0.
*
* @param string $price Price HTML.
* @param WC_Product $product Product instance.
* @return string.
*/
function my_wc_custom_get_price_html( $price, $product ) {
if ( $product->get_price() == 0 ) {
if ( $product->is_on_sale() && $product->get_regular_price() ) {
$regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) );
$price = wc_format_price_range( $regular_price, __( 'Free!', 'woocommerce' ) );
} else {
$price = '<span class="amount">' . __( 'Free!', 'woocommerce' ) . '</span>';
}
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'my_wc_custom_get_price_html', 10, 2 );
@DiviThemeExamples
Copy link

is it possible to add an extra condition to say, if its $0 AND in the xxx category to display FREE with plan ??

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