Last active
September 28, 2022 16:01
-
-
Save EricBusch/6414808bec9babdaf2849a13c7ce3a35 to your computer and use it in GitHub Desktop.
Preferred Terms, Term Variants and Excluded Terms [dfrpswc][datafeedr]
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 Age Group as an attribute. | |
* | |
* The attribute 'Age Group' with a slug of 'age-group' 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_color 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. | |
*/ | |
add_filter( 'dfrpswc_filter_attribute_value', function ( $value, $attribute, $post, $product, $set, $action ) { | |
$ai = new Dfrpswc_Attribute_Importer( 'age-group', $value, $attribute, $product ); | |
$ai->add_field( [ 'gender.name.description.category' ], 'gender', 'All Ages' ); | |
$ai->add_term( 'Girls', [ 'girl' ], [ 'womens', 'woman', 'women' ] ); | |
$ai->add_term( 'Boys', [ 'boy' ], [ 'mens', 'man', 'men' ] ); | |
$ai->add_term( 'Womens', [ 'female', 'womens', 'woman', 'women' ], [ 'girl', 'girls', 'child', 'children', 'kids', 'kid' ] ); | |
$ai->add_term( 'Mens', [ 'male', 'mens', 'man', 'men' ], [ 'boy', 'boys', 'child', 'children', 'kids', 'kid' ] ); | |
return $ai->result(); | |
}, 20, 6 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment