• Resolved paulnl

    (@paulnl)


    Hi,
    I use a feed from a manufacturer to upload to a WooCommerce custom field.
    The custom field expects a product id as input, but the feed is not aware of this.
    I use sku as the key to compare existing products with the feed.

    The imported field is called {metaparent_sku[1]} and the content has several values separated by | , for example:
    BDCD7 | BDAUX | BDCA1 | ADUP89
    These are unique product sku’s referring to products already in WooCommerce.

    What I’d like to do is replace the sku value with the corresponding product ID value in as it exists already in WooCommerce.

    I’ve been trying to use str_replace but can’t figure out how to set it up.

    Could you help?

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

    (@wpallimport)

    Hi @paulnl,

    I can see that we’ve already sent you an answer to this question in our support ticket system. To avoid confusion, let’s continue the discussion there if you still have any questions.

    For anyone else that comes across this, the solution was to use a custom PHP function ( https://www.wpallimport.com/documentation/developers/custom-code/inline-php/ ) to convert the SKUs to IDs. Here’s the example function:

    function my_get_ids( $skus ) {
    	$skus = explode( '|', $skus );
    	foreach ( $skus as $key => $sku ) {
    		$sku = trim( $sku );
    		$skus[ $key ] = wc_get_product_id_by_sku( $sku );
    	}
    	return implode( '|', $skus );
    }
    Thread Starter paulnl

    (@paulnl)

    Indeed for others who may experience the same issue: Meanwhile I received advise from Stack Overflow which worked perfectly.

    And thanks so much @wpallimport for volunteering your solution. Because of the working advice I received separately, I didn’t test yours.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I replace sku with product id?’ is closed to new replies.