Mailchimp Banner | Q2 2024

added by Latoya

Product Icon

Square

by  Woo
Accepting payments is easy with Square. Clear rates, fast deposits (1-2 business days). Sell online and in person, and sync all payments, items and inventory.

Keep New Lines in product description

I need the new lines in the product description to be kept when imported into WooCommerce.

New lines are incredibly important in product descriptions. They format text so it is human readable, but the sanitisation function that is used by WooCommerce Square rips out the newlines. I have beautifully formatted text in Square being condensed into a horribly robotic singular paragraph on my eCommerce store.

Thankfully though it’s an incredibly easy fix.

Currently you are using `wc_clean()` to sanitise every last bit of data that is imported from Square.

There is another default function available to use in the wc-formatting-functions.php file which retains new lines. It is called `wc_sanitize_textarea()`

On line 1131 within the function `create_product_from_square_data()` the following line appears:
// set description
$post_content = isset( $data[‘description’] ) ? wc_clean( $data[‘description’] ) : ”;

It can simply be updated to the following and new lines are retained in the product import.
// set description
$post_content = isset( $data[‘description’] ) ? wc_sanitize_textarea( $data[‘description’] ) : ”;

I have tested this on my own site and this works. New lines are retained during the import.

Please implement this! Human readable text is very important!

Cheers,
Joe

P.s. The ' should be an apostrophe but it’s being sanitised as if making a meta joke about sanitising user input lol. Please convert to apostrophes.

P.p.s. Fwiw, before I realised that additional sanitisation function existed I submitted an idea for making the `wc_clean()` accept a second parameter to keep the newlines. It would be a lot cleaner if that was implemented and you could just pass a boolean true parameter to `wc_clean()`.

https://woocommerce.com/forums/133476-woocommerce/suggestions/43645677-wc-clean-keep-line-breaks

Author

Current Status

Open

Last updated: June 16, 2021

0 comments

Log in to comment on this feature request.