Last active
July 14, 2020 11:03
-
-
Save Auke1810/a31d2d58aff4641cc87404bce362f887 to your computer and use it in GitHub Desktop.
Use parent description for product variations. By default the woocommerce product feed manager will use the description from the product variation. This code will make sure you use the parent product description for every product variation.
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
/** | |
* Use parent description for product variations | |
*/ | |
function use_parent_description_for_product_variations( $data, $feed_id, $product_id ) { | |
$wc_product = wc_get_product( $product_id ); | |
if ( $wc_product && ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) ) { | |
$parent_id = $wc_product->get_parent_id( 'feed' ); | |
$wc_parent = wc_get_product( $parent_id ); | |
$data['description'] = $wc_parent->get_description( 'feed' ); | |
} | |
// IMPORTANT! Always return the $data | |
return $data; | |
} | |
add_filter( 'wppfm_feed_item_value', 'use_parent_description_for_product_variations', 10, 3 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment