• Resolved newshop

    (@newshop)


    Hello,
    in my custom template, there is a part of code I would like to only appear for variable products.
    I tried to wrap that code like so:

    <?php 
    <if ( $product->is_type( 'variable' ) ) {
    printf('<div class="product-description">%s</div>', $item['product']->post->post_excerpt );
    }
    ?>

    But then I get “Fatal error: Call to a member function is_type() on null”

    How can I make this work?

    Thank you in advance 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @newshop,

    I think you need to use this instead:

    wc_get_product( $item['variation_id'] )->get_description()

    Thread Starter newshop

    (@newshop)

    Thank you, that works without error for variable product but for simple products it says: “Fatal error: Call to a member function get_description() on bool”
    But anyway, it shows the product description. I want the product attributes (e.g. “Size: M”) to show. My code form above shows the attributes when its a variable product (although it says product-description, so I dont understand why) and shows the product description when its a simple product. But as I already added the short description, simple products show the short description double. Thats why I wanted to use the above code wrapped in an if-statement to show only for variable products. Sorry, I hope you understand, its hard to explain 😀

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @newshop

    If you dump the $item you should be able to find a solution for that. If you prefer to not mess with code, I recommend you getting our Premium Templates extension where you have a column for the product description:

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

The topic ‘If-statement in Custom Template’ is closed to new replies.