Post Closed as "off-topic" by Howdy_McGee
2 indented code
source | link

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 );

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 );

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 );
1
source | link

Display FREE for $0 products in woocommerce ++++

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 );