Support

Account

Home Forums Add-ons Repeater Field Print different text based on the number of lines

Solving

Print different text based on the number of lines

  • I created a ‘measures and prices’ repeater
    Sub field |height| |width| |depth| |diameter| |price|
    on the product categories front end I would like to display the price with two variables,
    if sub field |price| has multiple lines = Price starting from € |price line 1|
    if sub field | price | has only one line = Price € |price line 1|
    Could you kindly tell me the code to enter?

  • What type of field is “price”?
    What is the return format of this field?

  • i don’t know if i did it right, this is the code i managed to do and it works

    <?php 
      if( have_rows('misure_e_prezzi')):
        $rows = get_field('misure_e_prezzi' );
    	$my_fields = get_field_object('misure_e_prezzi');
        $specific_row = $rows[0];
        $first_row_price = $specific_row['prezzo' ];
    	$count = (count($my_fields['value']));
        $valuta = '€ ';
    	?>
    <div class='prezzo'>
    <?php 
    if ($count ==1)
      echo $valuta .number_format( $first_row_price, 2, ',', ' ');?></div>
    
    <?php
    
    if ($count >1)    
    echo 'A partire da: '?>
    <div class='prezzo'>
      
      <?php 
     if ($count >1)    
    echo  $valuta  .number_format( $first_row_price, 2, ',', ' ');?></div>
    <?php
    endif;
    ?>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.