• Resolved dnlcrd

    (@stardeslebens)


    Because of a sync with a ERP system we have custom attributes (e.g. safety_regulations) with html markup and no other way to display them than in this custom attributes because of the ERP limitations. I am trying for hours and hours to the additional information tab display the markup as html output without success. <h2>, <br> etc are still shown as plain text in the frontend.

    I think this has something to do with echo wp_kses_post( $product_attribute[‘value’] ) in product-attributes.php but removing wp_kses_post here and just echo $product_attribute[‘value’] makes no difference at all?

    Is there another file that is used before this where kses is in use? Or is there a way to allow certain html markups in kses? I’ve tried hundreds of solutions on the web without look.

    Thanks a lot!

    The page I need help with: [log in to see the link]

Viewing 5 replies - 16 through 20 (of 20 total)
  • As I recall, the attributes are saved complete with any html. Check in wp_postmeta to confirm. But later, when you get use WooCommerce functions to fetch the attribute data, it will be filtered, and I couldn’t find a way to prevent that, so what worked was to fetch the attributes directly from the database with get_post_meta().

    @lorro no, when you set up a global attribute you cannot use any html in the term value’s name – when you save it, the html gets stripped immediately. And when you try to enter an , nothing is saved at all. As an alternative, is there a way to display the value’s desription instead of the value’s name in my mentioned code? Because allowing html in the value description is easy.

    I’ve checked and yes you’re right, global attributes are not saved with any html. The original post was about custom attributes and they can be saved with html.

    I don’t think attrubutes have descriptions, but terms do. So your code will need to cycle through the attributes, and foreach attribute, get the terms. Then cycle through the terms and get the description from each term.

    Probably best to stay away from WooCommerce functions because they will lead down a route that isn’t right for what you want to do.

    Sorry, not tested.

    @lorro Attribute VALUES can have descriptions. When you set up an attribute value, for example “green”, there is an optional field for the description. But I don’t know how to change my code to display this description instead of the value’s name. Something like

    $attributes_data[] = $attribute_name . ': ' . $term_description;

    does not work.

    An attribute value is called a term, so you’d use get_the_terms() to get an array of term objects for a given attribute, then cycle through the terms and use
    $term->description to get the description.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘HTML markup in attribute values’ is closed to new replies.