HTML in WooCommerce settings

I need to append a default text block to each product description (same text for each and every product) in WooCommerce. So I’ve created simple plugin which adds new settings field as rich text editor (wp_editor) into “WooCommerce > Settings > Catalog” tab.

All works fine and I can enter/save plain text, but it strips any HTML tags. I believe tags are stripped by woocommerce_clean in settings-save.php

Read More
if ( isset( $value['id'] ) && isset( $_POST[$value['id']] ) ) {
 update_option($value['id'], woocommerce_clean($_POST[$value['id']]));
} elseif( isset( $value['id'] ) ) {
 delete_option($value['id']);
}

How can this be fixed without changing core code?

Related posts

Leave a Reply

1 comment

  1. The woocommerce_clean function: return trim( strip_tags( stripslashes( $var ) ) ); is pretty much going to stip out any html. You may be able to use core WordPress sanitize and escaping functions, but no guarantee how WooCommerce is going to react.

    Take a look at Data Validation docs on the WordPress Codex for other options.

    Since your boilerplate text is the same on every product your simplest solution may be copy the default WooCommerce template(s) into your theme’s directory and editing the file(s) as needed. Seems like overkill to write a user interface for this.

    If you want to display this in the product ‘Short Description’ then the file would be ../wp-content/plugins/woocommerce/templates/single-product/short-description.php. Copy that file to your your theme’s directory ../wp-content/themes/***your theme directory***/woocommerce/single-product/short-description.php

    Once you’ve copied you can edit the file without worrying about your changes being overwritten when you update WooCommerce.

    The docs on customizing the templates are at WooCommerce docs.

    NOTE: If you want this in the Description tab you can use the file ../wp-content/plugins/woocommerce/templates/single-product/tabs/description.php