• I’d like to add a custom attribute text to each product on the catalog page (a tagline), and as I understand it, I need to use the following php below:

    <?php echo $_product->get_attribute( 'tagline' );?>

    (tagline being the name of the attribute I’ve set)

    However, this produces an error, presumably because not all products have this attribute set.

    So I’m guessing that I need to add some additional code to check whether the given attribute is available, before the php above.

    Any pointers on how to to do this?

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Roy Ho

    (@splashingpixelscom)

    Yes the product class has a method called “has_attributes” which you can use.

    Thread Starter aand

    (@aand)

    Ah thanks, sounds good – any pointers on the php for this (my php skills are very limited)?

    Roy Ho

    (@splashingpixelscom)

    has_attributes method returns a boolean true or false…So if your new class is called $_product assuming you used the abstract method of $_product = get_product( $id ); then your code would look something like this:

    if ( $_product->has_attributes() ) {
         echo $_product->get_attribute( 'tagline' );
    }
    Thread Starter aand

    (@aand)

    Much appreciate – will give that a go!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom attributes on catalog page?’ is closed to new replies.