Last active
April 20, 2022 07:02
-
-
Save Auke1810/ba1f71311df86b19b580ff81c5216d25 to your computer and use it in GitHub Desktop.
This is an example how to derive Taxonomy data from Wordpress and add this to the product feed created with the Woocommerce product feed manager from wpmarketingrobot.com You will need to edit the variabels in order to make it more readable for your taxonomy.
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
/** | |
* | |
*/ | |
function wppfm_add_taxonomy_data_to_feed( $data, $feed_id, $product_id ) { | |
// Get the product_badges taxonomy data. | |
$taxonomyName = 'product_taxonomy_data'; // use the name of your own taxonomy | |
$taxonomyData = wp_get_post_terms( $product_id, $taxonomyName ); | |
if ( $taxonomyData ) { | |
$product_taxonomy_data = array(); | |
// Get the selected Taxonomy data for this product. | |
foreach( $taxonomyData as $taxData ) { | |
array_push($product_taxonomy_data, $taxData->name); | |
} | |
// Place the Taxonomy data in the feed as a comma separated string. | |
$data['custom_label_0'] = implode(',', $product_taxonomy_data); | |
} | |
// Always return data! | |
return $data; | |
} | |
add_filter( 'wppfm_feed_item_value', 'wppfm_add_taxonomy_data_to_feed', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're not familiar with using filters in your wp-admin, the best and easiest way to do this is by using a plugin like "Code Snippets" (https://wordpress.org/plugins/code-snippets/). And here you can find a great video explaining the use of this plugin https://www.youtube.com/watch?v=I1_ZqnQmwJs.
After activating the Code Snippets plugin you can use the code I previously mentioned to add the functionality.