Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Last active April 19, 2017 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricBusch/a9e7c909d792493c3b3a689720e8caeb to your computer and use it in GitHub Desktop.
Save EricBusch/a9e7c909d792493c3b3a689720e8caeb to your computer and use it in GitHub Desktop.
This code is for using the Comparison Sets plugin on products not imported by the WooCommerce Importer plugin. It will use the SKU value as the EAN value so that Comparison Sets can be generated from EAN values as well as the product name for products added to WooCommerce manually. [datafeedr][dfrcs]
<?php
/**
* Add "sku" value as "ean" to $source.
*
* @param array $source
* @param WC_Product $product
*
* @return array Updated $source array.
*/
add_filter( 'dfrcs_wc_source', 'mycode_add_ean_to_source', 20, 2 );
function mycode_add_ean_to_source( $source, $product ) {
if ( isset( $source['id'] ) ) {
return $source;
}
$ean = $product->get_sku();
$source['ean'] = $ean;
return $source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment