• Resolved eduits

    (@eduits)


    Hi,

    For a client I have to import an XML file with products and there categories.
    In this file there is a field called <E2C_CatStruc>030302</E2C_CatStruc>
    Now I have to match this field with the custom field I created in Woocommerce categories.

    I have a separate XML file for importing categories which is build up like this:

    <row>
    <Code>030302</Code>
    <Description_NL>Colorstix</Description_NL>
    </row>

    I added a custom field in the Woocommerce product categories.
    Every category has an extra field called: categoryid

    I imported the categories with Name and Slugs, and the custom field is filled with the <Code>030302</Code>.

    My question is:

    How can I import the products matching the <E2C_CatStruc>030302</E2C_CatStruc> to the custom field I created in the Woocommerce categories called categoryid so that the product is imported into the category name: Colorstix

    Thank you very much.

    • This topic was modified 4 years, 4 months ago by eduits.
    • This topic was modified 4 years, 4 months ago by eduits.
    • This topic was modified 4 years, 4 months ago by eduits.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter eduits

    (@eduits)

    Solved

    <?php
    function my_get_category( $ids ) {
    	if ( ! empty( $ids ) ) {
    		$return = array();
    		$ids = explode( ",", $ids );
    		foreach ( $ids as $id ) {
    			$id = trim( $id );
    			$term = get_terms( array(
    				'taxonomy' => 'product_cat',
    				'hide_empty' => false,
    				'meta_query' => array(
    					'key' => 'intercambio_cat',
    					'value' => $id,
    					'compare' => '='
    				)
    			) );
    			if ( ! empty( $term ) ) {
    				$return[] = $term[0]->slug;
    			}	
    		}
    		if ( ! empty( $return ) ) {
    			return implode( ">", $return );
    		}
    	}	
    }
    
    ?>
    • This reply was modified 4 years, 4 months ago by eduits.
Viewing 1 replies (of 1 total)
  • The topic ‘Import products while matching custom field for category’ is closed to new replies.