Created
April 12, 2023 10:55
-
-
Save Auke1810/879916b6df820a4aa1dd5682520faaaa to your computer and use it in GitHub Desktop.
voeg product attributen toe aan een custom product feed.
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_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