admin管理员组

文章数量:1130349

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.

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.

Share Improve this question asked Nov 22, 2018 at 18:52 joloshopjoloshop 211 silver badge8 bronze badges 4
  • There's an unwanted } after the get_post_meta() call - true );}, and what is that $meta == ''; doing? – Sally CJ Commented Nov 22, 2018 at 19:46
  • removed the } the $meta == ' '; is checking if meta is empty. – joloshop Commented Nov 22, 2018 at 19:56
  • still not working just stuck – joloshop Commented Nov 22, 2018 at 20:14
  • Check and try my answer? – Sally CJ Commented Nov 22, 2018 at 20:31
Add a comment  | 

1 Answer 1

Reset to default 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;
    }
}
?>

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.

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.

Share Improve this question asked Nov 22, 2018 at 18:52 joloshopjoloshop 211 silver badge8 bronze badges 4
  • There's an unwanted } after the get_post_meta() call - true );}, and what is that $meta == ''; doing? – Sally CJ Commented Nov 22, 2018 at 19:46
  • removed the } the $meta == ' '; is checking if meta is empty. – joloshop Commented Nov 22, 2018 at 19:56
  • still not working just stuck – joloshop Commented Nov 22, 2018 at 20:14
  • Check and try my answer? – Sally CJ Commented Nov 22, 2018 at 20:31
Add a comment  | 

1 Answer 1

Reset to default 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;
    }
}
?>

本文标签: phpShow different button text if no content