Last active
November 11, 2018 15:26
-
-
Save EricBusch/e0f7fa8dcbb59e65bc1874c3c21287c2 to your computer and use it in GitHub Desktop.
Normalize brand names before importing as WooCommerce attribute. [datafeedr][dfrpswc]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add the product's brand as an attribute. | |
* | |
* The attribute "Brand" with a slug of "brand" must already exist here: WordPress Admin Area > Products > Attributes | |
* | |
* @param array|string $value The current value of the $attribute for this $post. | |
* @param string $attribute The slug of the attribute. Examples: pa_brand or pa_shoe-size | |
* @param array $post An array of post data including ID, post_title, post_status, etc... | |
* @param array $product An array of product data returned from the Datafeedr API. | |
* @param array $set A post array for this Product Set with an array key of postmeta containing all post meta data. | |
* @param string $action The action the Product Set is performing. Value are either "insert" or "update". | |
* | |
* @return array|string The updated attribute's value. | |
*/ | |
function mycode_import_brand_attribute( $value, $attribute, $post, $product, $set, $action ) { | |
$ai = new Dfrpswc_Attribute_Importer( 'brand', $value, $attribute, $product ); | |
$ai->add_field( [ 'brand' ] ); | |
$ai->add_term( "Aerobie", [ "Aerobie, Inc." ] ); | |
$ai->add_term( "Black Diamond", [ "Black Diamond Equipment", "Black Diamond Inc" ] ); | |
$ai->add_term( "CAMP USA", [ "camp", "camp usa - cassin" ] ); | |
$ai->add_term( "Crucial Coffee", [ "crucial brands", "crucial-coffee" ] ); | |
return $ai->result(); | |
} | |
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_import_brand_attribute', 20, 6 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment