Finally found a solution. I’m putting it here in case anyone else needs it. I haven’t fully tested if there are bugs, but it all seems good. This takes the short description in your product and makes sure it puts it as the <description> in the product feed generated, it also appears for any variations of those items. I’m sure the logic can be used for other purposes. So you may want to refer to it. I simply put it in my child theme’s functions.php but it could go in a plugin. I’ll wait till my feed gets updated to Pinterest then come back and confirm if everything is good.
//pulls short description and puts it in pinterest for woocommerce product feed
function use_short_description_in_pinterest_feed( $xml, $product ) {
// Ensure we're working with the correct product (parent if necessary)
if ( $product->is_type('variation') ) {
$product = wc_get_product( $product->get_parent_id() );
}// Retrieve the short description
$short_description = $product->get_short_description();
// Fallback to excerpt if short description is empty
if ( empty( $short_description ) ) {
$short_description = get_the_excerpt( $product->get_id() );
}
// Sanitize and prepare the description for XML
$description = '<![CDATA[' . wp_strip_all_tags( $short_description ) . ']]>';
// Replace the existing <description> tag with the short description
$xml = preg_replace( '/<description>.*?<\/description>/', '<description>' . $description . '</description>', $xml );
return $xml;
}
// Hook into the Pinterest feed generation to apply the short description
add_filter( 'pinterest_for_woocommerce_feed_item_xml', 'use_short_description_in_pinterest_feed', 10, 2 );
-
This reply was modified 12 hours, 3 minutes ago by
CanadianKevbo.
Hello @canadiankevbo,
Glad to know that the issue has been resolved now and thank you for sharing the solution and contributing to the WooCommerce Community.
Should you have further inquiries, kindly create a new topic here.
Cheers!
My feed updated last night and had the short description in the details properly with no errors. I hope the code above helps!
