Support » Plugin: Import any XML or CSV File to WordPress » Creating categories from titles or descriptions

  • Resolved blecha

    (@blecha)


    Hi,
    in my XML file there are products from different brands with titles such as:

    – Adidas Nemeziz 20.1 football boots
    – Nike Mercurial Superfly football boots
    – Puma King Pro football boots

    but in the XML file all the products are put in just one category “Football boots”

    I would like to create my own categories in woocommerce:

    – Adidas football boots
    – Nike football boots
    – Puma football boots

    and categorize products by titles (if title contains adidas > put into category adidas football boots).

    Is there any way how can do this? I suppose I will need to use category mapping tool (https://d.pr/i/GyUWis), but I do not know how. Should I use some PHP code?

    Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hey @blecha,

    I’d suggest using a custom PHP function for this: https://www.wpallimport.com/documentation/developers/custom-code/inline-php/. Here’s an example function:

    For example, if the first word of the product title is always the brand, and you always want the category to be “Brand_name_here Football Boots”, you could use this:

    function my_pick_category( $title ) {
    	$title = explode( ' ', $title );
    	return reset( $title ) . ' Football Boots';
    }

    Or, if you need to do a search for a word and then decide the category, something like this would work:

    function my_pick_category( $title ) {
    	$categories = array(
    		'Adidas' => 'Adidas Football Boots',
    		'Nike'   => 'Nike Football Boots',
    		'Puma'   => 'Puma Football Boots'
    	);
    	
    	foreach ( $categories as $keyword => $category ) {
    		if ( stristr( $title, $keyword ) ) {
    			return $category;
    		}
    	}
    }
    Thread Starter blecha

    (@blecha)

    Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.