• I decided to add ' €'.'/ sett.' in this function:

    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true ). ' €'.'/ sett.' ;
    if ( ! empty( $display_price2)) {
    $display_price2='<div class="listino_prezzi">'. $display_price2 .'</div>';
    }
    

    But I’m realizing that, doing so, the conditional if ( ! empty( $display_price2)) is unusefull because the variable $display_price2 will never be empty. The is a remedy to this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Just add it later

    
    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true );
    if ( ! empty( $display_price2)) {
    	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
    }
    Thread Starter sacconi

    (@sacconi)

    Also in this way the variable is printed. I tryed to put also .' &euro; / sett out of the div but i got printed both a white div and under this “€ / sett.”

    Moderator bcworkz

    (@bcworkz)

    Why do you want “€ / sett” outside of the div? Divs are normally block level elements, so added content will typically appear below the div and any margins and padding from the div will separate the two.

    If you want “€ / sett” styled differently than other div content but still on the same line, place it within <span> tags, which display as inline elements. Assign a class attribute to the span so you can target it with CSS separately from other div content.

    Thread Starter sacconi

    (@sacconi)

    I dont want it out of the div, I want the conditional be working

    Here you shouldnt see the grid with green lines: https://test.sacconicase.com/lignano-sabbiadoro-appartamento-al-1-piano-con-terrazzo-spazioso-zona-ufficio-spiaggia-16/#titolo_listino_prezzi

    because both get_the_author_meta and get_post_meta are empty, but “€ / sett ruins the function

    Sorry, what was wrong with my code? Did you try it?

    I just spotted you added a space as well so to make the empty work then trim()

    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true );
    if ( ! empty( trim( $display_price2 ) )) {
    	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
    }
    Thread Starter sacconi

    (@sacconi)

    It would have worked (it has worked), but the problem is that now there is no more that space, it is replaced with a ‘ <strong>’ , with a space too, so when I use

    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' <strong>' . get_post_meta( $post->ID, 'function_prezzo_secondo', true ).'</strong>';
    if ( ! empty(trim( $display_price2 ) )) {
    	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
    }
    

    I still have this problem (with or without the trim) 🙁 sorry for this changment, I’m trying to adjust the code to the project

    Moderator bcworkz

    (@bcworkz)

    We’re now discussing the same code snippet in two different topics. The cross-talk can be confusing for everyone involved. This is why we discourage duplicate topics. I realize that these topics were initially focused on two different aspects, but now they’ve run together.

    To keep further replies in one place, this topic is now closed. Please continue at https://ww.wp.xz.cn/support/topic/crating-a-function-to-set-discount-on-prices/#post-17049761

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘conditional ineffective’ is closed to new replies.