Because you can’t input anything other than a price in WooCommerce, it makes it difficult when using WooCommerce as an event platform to display paid events as FREE, or even adding labels like SEE DETAILS, or REGISTRATION REQUIRED. This little hack replaces the price with pre-defined words.
So a price of $0 is displayed as FREE
A price of $99999 is displayed as SEE DETAILS
A price of $99998 is displayed as CANCELLED
A price of $99998 is displayed as REGISTRATION
Use this hackery for good.
// FREE ---------------------------------
add_filter( 'woocommerce_get_price_html', 'wally_price_free_empty', 9999, 2 );
function wally_price_free_empty( $price, $product ){
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
$price = '<span class="woocommerce-Price-amount amount">FREE</span>';
}
return $price;
}
// SEE DETAILS ---------------------------------
add_filter( 'woocommerce_get_price_html', 'wally_price_details', 9999, 2 );
function wally_price_details( $price, $product ){
if ( '' === $product->get_price() || 99999 == $product->get_price() ) {
$price = '<span class="woocommerce-Price-amount amount">SEE DETAILS</span>';
}
return $price;
}
// CANCELLED ---------------------------------
add_filter( 'woocommerce_get_price_html', 'wally_price_cancelled', 9999, 2 );
function wally_price_cancelled( $price, $product ){
if ( '' === $product->get_price() || 99998 == $product->get_price() ) {
$price = '<span class="woocommerce-Price-amount amount">CANCELLED</span>';
}
return $price;
}
// REGISTRATION ---------------------------------
add_filter( 'woocommerce_get_price_html', 'wally_price_registration', 9999, 2 );
function wally_price_registration( $price, $product ){
if ( '' === $product->get_price() || 99997 == $product->get_price() ) {
$price = '<span class="woocommerce-Price-amount amount">REGISTRATION</span>';
}
return $price;
}