WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Custom attributes on catalog page? (5 posts)

  1. aand
    Member
    Posted 1 year ago #

    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/

  2. Roy Ho
    Member
    Posted 1 year ago #

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

  3. aand
    Member
    Posted 1 year ago #

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

  4. Roy Ho
    Member
    Posted 1 year ago #

    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' );
    }
  5. aand
    Member
    Posted 1 year ago #

    Much appreciate - will give that a go!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic