• Hi.
    I have a woocoomerce
    on the product page I have a div.
    I need that div is hidden when the product price is less than 200.
    Could anyone help me?
    I tried with this:

    <Div id = “foo” <? Php $ price = $ product-> get_price_html (); if (($ price> 200)) {echo ‘style = “display: none;”‘; }? >>

    text
    </ Div>

    any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Have you checked to see what kind of values are output by get_price_html()? Try echoing that in the page and see how you might be able to compare that data with your price.

    Moderator bcworkz

    (@bcworkz)

    ancawonka is suggesting that get_price_html() is returning something that cannot be compared to 200, which is quite likely since it is returning an HTML string and you are trying to compare it to an integer. As suggested, echo out the returned string and decide how to extract just a price value without other HTML, nor currency signs, nor thousands separators, but keep the decimal point. preg_match() might work for this.

    Besides a type mismatch, the code you tried has a few syntax errors. It may be the forum’s parser corrupted your code because you didn’t put your code between backticks. Here is a better version, though the type mismatch issue remains:

    <div id = "foo" <?php $price = $product->get_price_html(); if ( 200 > $price ) { echo 'style = "display: none;"'; } ?> >
      text
    </div>

    Spaces in some places is a stylistic choice, but in other places it causes a parsing error. Same for upper/lower case, sometimes a stylistic choice, other times it makes a difference. With time you’ll learn where it matters and where it doesn’t.

    Thread Starter renitro

    (@renitro)

    Thank you bcworkz and ancawonka.
    That was the problem.
    I replaced get_price_html () by DISPLAY_PRICE get ()
    now it works

    <div id = “foo” class=”demofinancia” <?php $muestra = $product->get_display_price(); if ( 200 > $muestra ) { echo ‘style = “display: none;”‘; } ?> > TEXT </div>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘hide div product price’ is closed to new replies.