• Resolved metaltemple

    (@metaltemple)


    So here’s the problem. There’s an eshop that’s using qtranslate and all product descriptions are exported in the following form:
    [:en]Blahblah 1[:el]Blahblah 2[:]
    I’m trying to remove everything in between (and including) the [:en] and [:el] tags and then remove the remaining [:] tag so that only Blahblah 2 is exported
    The regex for these two are:
    /\[:en\].*?\[:el\] and /\[:\]

    I’ve tried preg replace and nothing seems to work. What are the valid commands to replace these two instances with null?

    Thanks!

    • This topic was modified 4 years, 5 months ago by metaltemple.
    • This topic was modified 4 years, 5 months ago by metaltemple.
    • This topic was modified 4 years, 5 months ago by metaltemple.
    • This topic was modified 4 years, 5 months ago by metaltemple.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ohidul Islam

    (@wahid0003)

    @metaltemple give me a description of a product here.

    Thread Starter metaltemple

    (@metaltemple)

    Hello and thanks for the swift reply!

    This is a typical description
    [:en]Available in two delightful options of red or grey.[:el]Διαθ?σιμα σε δυο χρ?ματα, κ?κκινο και γκρι.[:]
    Just need to keep the “Διαθ?σιμα σε δυο χρ?ματα, κ?κκινο και γκρι.” part.

    Plugin Author Ohidul Islam

    (@wahid0003)

    @metaltemple You have to add the below code into your child theme functions.php file or you can use the code snippet plugin to apply the filter.

    /**
     * Remove short codes from description.
     * 
     * @param string $description Product Description.
     * @param WC_Product $product Product Object.
     * @param array $feed_config Feed Configuration.
     * @return string
     */
    function woo_feed_get_description_attribute_callback($description,$product,$feed_config){
    //    if('google'===$feed_config['provider']){
            $description= str_replace(array('[:en]','[:el]','[:]'),'',$description);
    //    }
        return $description;
    }
    add_action('woo_feed_get_description_attribute','woo_feed_get_description_attribute_callback',10,3);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Regex in Command’ is closed to new replies.