function php

Closed

Import WP Updated 2 years ago 6 Replies

Konstantin asked 2 years ago on February 9, 2023 at 4:01 pm

Hello! import text “Promocode is not required_x000D_ Sale Price: €33.99_x000D_ China Warehouse_x000D_ Free Shipping”, this text contains the characters “_x000D_”, how can I replace these characters with a space or input?

J

James replied Support Agent

2 years ago on February 9, 2023 at 11:10 pm

Hi Konstantin,

You can add the following custom method to your themes functions.php file

<?php

/**
 * Custom method to search and replace a string with another
 *
 * @param string $input The string to search in.
 * @param string $search The string we are searching for.
 * @param string $replace String to replace the search with.
 *
 * @return string
 */
function iwphd_search_replace($input = '', $search = '', $replace = '')
{
    $input = str_replace($search, $replace, $input);

    return $input;
}

On the template fields step of the importer, when you are selecting what data to import, wrap the data selection e.g. {0} in the custom method as follows

[iwphd_search_replace("{0}", "_x000D_", " ")]

This should update the preview to replace _x000D_ with a space.

 

KC

Konstantin replied

2 years ago on February 10, 2023 at 2:16 pm

Thank you for the answer. But unfortunately the function does not work.

J

James replied Support Agent

2 years ago on February 10, 2023 at 2:32 pm

Are you able to attach the following:

* A screenshot of the field you have used the function in?
* An example csv/xml file you are using.
* Goto Tools > Import WP > Settings / Tools > Import / Export > And export and attach a copy of your importer.

KC

Konstantin replied

2 years ago on February 10, 2023 at 2:50 pm

1. screenshot fail "scren"

2. https://export.admitad.com/en/webmaster/websites/2283898/coupons/export/?website=2283898&region=00&language=&only_my=on&advcampaigns=20543&keyword=&id=keyword&code=5q70to9aqa&user=apokalipsis1805%40gmail.com&format=xlsx

3. Fail Import / Export "ImportWP-export-2023-02-10"

J

James replied Support Agent

2 years ago on February 10, 2023 at 3:41 pm

Thanks,

I have updated the base importer, if you can download and activate the latest development version, once activated the preview text should show the character replacements instead of the function.

James

KC

Konstantin replied

2 years ago on February 10, 2023 at 3:51 pm

Thank you for the answer. You are a magical person