Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Created April 12, 2023 10:55
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/879916b6df820a4aa1dd5682520faaaa to your computer and use it in GitHub Desktop.
Save Auke1810/879916b6df820a4aa1dd5682520faaaa to your computer and use it in GitHub Desktop.
voeg product attributen toe aan een custom product feed.
function wppfm_add_product_attributes( $attributes, $feed_id, $product_id ) {
$wc_product = wc_get_product( $product_id ); // Get the WC_Product Object
if ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) {
$product_attributes = $wc_product->get_attributes(); // Get the product attributes
// Loop through the attributes and add them to the $attributes array
foreach ( $product_attributes as $key => $value ) {
if ( $value ) {
$attributes[ $key ] = $value;
}
}
}
// IMPORTANT! Always return the $attributes
return $attributes;
}
add_filter( 'wppfm_feed_item_value', 'wppfm_add_product_attributes', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment