Skip to content

Instantly share code, notes, and snippets.

@rynaldos rynaldos/wc-show-free.php
Last active Sep 6, 2017

Embed
What would you like to do?
[WooCommerce 3.0+] Re-instate "Free" instead of 0 value
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 );
@mcwe

This comment has been minimized.

Copy link

mcwe commented Aug 3, 2017

is there a way to make this snippet multi language so it can say free in several languages, depending on what language is currently used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.