Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active April 20, 2022 07:02
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 Auke1810/ba1f71311df86b19b580ff81c5216d25 to your computer and use it in GitHub Desktop.
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.
/**
*
*/
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 );
@Auke1810
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment