lundi 22 avril 2019

How do I add a variable to a string when the variable is in the "if" statement?

I can't get the string to read out what I want in the final else statement. I want {$start} to read out what the start is set to in the if statement.

I've tried {$start}, .$start, %d.

if ( $time < $start ) {

    $time_until_opens = ( $start->getTimestamp() - $time->getTimestamp() ) / 60;


    if ( $time_until_opens <= 5 ) {
        $this->message = __( 'Happy Hour Starts Soon', 'my-listing' );
        $this->status = 'Happy Hour Soon';

        return true;
    } elseif ( $time_until_opens <= 30 ) {
        $this->message = sprintf( __( 'Happy Hour In %d Minutes', 'my-listing' ), ( round( $time_until_opens / 5 ) * 5 ) );
        $this->status = 'opening';

        return true;
    } else {
        $this->status = 'closed';
        $this->message = __( 'Happy Hour At {$start}', 'my-listing' );
    }
}


$start is set to 4:00 PM. It doesn't show 4:00 PM. It shows {$start}.

Aucun commentaire:

Enregistrer un commentaire