• Resolved pjindras

    (@pjindras)


    Hello, can i ask you, i need a little help with my product additional information tab. I am using data feed from my suppliers, but while importing, i see some data like this:

    https://ibb.co/QKdTbQ2

    How can i allow html code there?

    Thank you!

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • WooCommerce runs attribute values through a filter to remove real html and show it in a printable format.

    The way forward is to retrieve the attribute values direct from the database. You’ll need to make a custom template for product-attributes.php. The copy goes at:
    themes/your-child-theme/woocommerce/single-product/product-attributes.php

    In the copy, use something like:

    $product_id = $product->get_id();
    $ats = get_post_meta( $product_id, '_product_attributes', true );
    foreach( $ats as $at ) {
      $product_attribute['value'] = html_entity_decode( $at['value'], ENT_COMPAT | ENT_HTML5 );
      }
    }

    Some PHP skills will be necessary to get it working.

    This only works for custom attributes. These are saved with html. However, global attributes are stripped of any html before saving to the database.

    WooCommerce strips html as a safety feature. If you are using unfiltered html, be sure it comes from a trusted source.

    Thread Starter pjindras

    (@pjindras)

    Ok, thank you, so the product-attributes.php should look like this? Can i just add your code or replace it? In /your-child-theme/woocommerce/single-product/product-attributes.php (I am using twenty twenty theme)

    defined( 'ABSPATH' ) || exit;
    
    if ( ! $product_attributes ) {
    	return;
    }
    ?>
    <table class="woocommerce-product-attributes shop_attributes">
    	<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
    		<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
    			<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
    			<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
    		</tr>
    	<?php endforeach; ?>
    </table>
    $product_id = $product->get_id();
    $ats = get_post_meta( $product_id, '_product_attributes', true );
    foreach( $ats as $at ) {
      $product_attribute['value'] = html_entity_decode( $at['value'], ENT_COMPAT | ENT_HTML5 );
      }

    No, it was meant to be an approach, not exact code. Try this:
    https://pastebin.com/Tm8SG9kk

    If it doesn’t work for you, please post the address of a relevant product page.

    Thread Starter pjindras

    (@pjindras)

    It works perfect, thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘HTML in product additional information tab’ is closed to new replies.