You are here:  » Text before it not contains

Text before it not contains

Submitted by sirmanu on Sun, 2019-09-22 17:59 in

Hi David.
Is any filter to "text before" a product name (also working with placeholders % or {}) when some string is not present.

I have products from BRAND, and some have the brand in the product title, and others not.

I want to prepend BRAND when BRAND is not present in the product name.
I have tried search and replace, and the text before, but it is not working as expected, because they don't have always the brand in the beginning.

Thank you!

Submitted by support on Mon, 2019-09-23 08:29


Probably easiest to add a new "Text Before If Not Contains" filter - here's the code to add to includes/filter.php:

  /* textBeforeIfNotContains */
  $filter_names["textBeforeIfNotContains"] = "Text Before If Not Contains";
  function filter_textBeforeIfNotContainsConfigure($filter_data)
  function filter_textBeforeIfNotContainsValidate($filter_data)
    if (!$filter_data["text"])
      widget_errorSet("text","required field");
  function filter_textBeforeIfNotContainsExec($filter_data,$text)
    if (stripos($text,$filter_data["text"])===FALSE)
      return filter_recordPlaceholders($filter_data["text"]).$text;
    return $text;

Hope this helps!


Submitted by sirmanu on Mon, 2019-09-23 22:34

Awesome David, it is working as expected