0

With this code:

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';
            }
         ?>

I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.

Tried

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';

            } else {
            $class .= ' coupon-hidden';
            $meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} 
            $meta == '';
            $button_text = 'Angebot anzeigen';

            }
         ?>

But just getting empty page.

  • There's an unwanted } after the get_post_meta() call - true );}, and what is that $meta == ''; doing? – Sally CJ Nov 22 '18 at 19:46
  • removed the } the $meta == ' '; is checking if meta is empty. – joloshop Nov 22 '18 at 19:56
  • still not working just stuck – joloshop Nov 22 '18 at 20:14
  • Check and try my answer? – Sally CJ Nov 22 '18 at 20:31
0

First off, as I mentioned in the comment, you got a syntax error here, where there's an unwanted }:

$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} // <- that }

(Updated answer — Previous code were removed since they didn't work for you.)

So if you want to show the special text when $clpr_options->coupon_code_hide does not evaluate to a true and that the field clpr_coupon_code is empty; try this:

<?php if ( $clpr_options->coupon_code_hide ) {
    $class .= ' coupon-hidden';
    $meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );

    // If clpr_coupon_code is empty.
    if ( ! $meta ) {
        $button_text = 'Angebot anzeigen';
    // If clpr_coupon_code is not empty.
    } else {
        $button_text = fl_get_option( 'fl_lbl_show_coupon' );
        $button_text = '<i class="icon-lock"></i>' . $button_text;
    }
}
?>
  • Thanks a lot for the help, but unfortunately its not working still shows the content of $button_text = '<i class="icon-lock"></i>' . $button_text;all the time – joloshop Nov 22 '18 at 20:31
  • In that case, then it's probably because $clpr_options->coupon_code_hide is always true in your tests. Let me update the answer. – Sally CJ Nov 22 '18 at 20:33
  • yes $clpr_options->coupon_code_hide is always true $button_Textsould only change if clpr_coupon_codeis empty. – joloshop Nov 22 '18 at 20:41
  • WOW just great. ITS WORKING, thanks a lot. Was just starting to go into the same directions. But just a newbie. Still a long way ;-) Again THANKS – joloshop Nov 22 '18 at 20:46
  • You're welcome! And it's alright, nobody started as a pro.. just keep on learning and you'll become better in time. :) – Sally CJ Nov 22 '18 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.