Ask your WordPress questions! Pay money and get answers fast! (more info)

PHP syntax error WordPress

  • SOLVED

What's wrong with the formatting of this code?

<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) { ?>

<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>

} else {
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>

}
<?php endif; ?>

Answers (4)

2017-01-25

mod mi answers:

Hi, there are no <?php ?> tags on "} else {" and the last closing "}". Also you are closing the conditional with endif; but your are using curly brackets before.

Check with curly brackets:

<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) { ?>

<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>

<?php } else { ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>

<?php } ?>


Check if you want with endif; :

<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) : ?>

<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>

<?php else: ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>

<?php endif; ?>

2017-01-25

Jayaram Y answers:

It must be like this

<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) { ?>

<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>
<?php } else { ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>
<?php } ?>


If you want to use endif it must be like this:


<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) :?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>
<?php else : ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>
<?php endif; ?>

2017-01-25

Shoeb mirza answers:



<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) : ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>
<?php else: ?>
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>
<?php endif; ?>

2017-01-25

Krishna Tiwari answers:

Hi,
Following is the correct code:

<?php if ( rcp_registration_is_recurring() && !is_user_logged_in() ) { ?>

<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td></td>
</tr>

<?php }else {
<tr>
<td><?php echo rcp_get_subscription_name( rcp_get_registration()->get_subscription() ); ?></td>
<td><?php echo ( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ) > 0 ) ? rcp_currency_filter( number_format( rcp_get_subscription_price( rcp_get_registration()->get_subscription() ), rcp_currency_decimal_filter() ) ) : __( 'free', 'rcp' ); ?></td>
</tr>
<?php
}
?>