1

I have a function that changes the $0 to say "FREE"... but now i want to extend this further, but im stuck ... i want to edit the following so that it changes $0 -> FREE .... AND when the product is $0 and in xxx category, then it should say "FREE WITH PLAN"

/*0 to free*/
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 );

closed as off-topic by Howdy_McGee May 10 '17 at 14:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • You should have a look at the has_category function. – luke May 10 '17 at 10:09

Browse other questions tagged or ask your own question.