Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active October 21, 2020 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Auke1810/294ac95503b6fba5114d32c846774635 to your computer and use it in GitHub Desktop.
Save Auke1810/294ac95503b6fba5114d32c846774635 to your computer and use it in GitHub Desktop.
Solve "Item to big" error in Merchant center by removing Visual composer tags and html from description and making sure the text left is not to large.
<?php
function remove_vc_description( $attributes, $feed_id, $product_id ) {
//remove VC code
$clean_description = preg_replace("/\[(\/*)?vc_(.*?)\]/", '', $attributes['description'] );
// Strip html from description attributes
// allow given tags with allowedTags
$allowedTags = "";
$clean_description = strip_tags($clean_description, $allowedTags);
// Check if the text is larger as the max 5000 characters that Google limits
// If so strip the text
$max_length = 500; // 5000 is the max but Google also adivses 500 for a better User experience.
if (strlen($clean_description) > $max_length)
{
$clean_description = wordwrap($clean_description, $max_length);
$clean_description = substr($clean_description, 0, strpos($clean_description, "\n"));
}
$attributes['description'] = $clean_description;
// IMPORTANT! Always return the $attributes
return $attributes;
}
add_filter( 'wppfm_feed_item_value', 'remove_vc_description', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment