Link to home
Create AccountLog in
Avatar of Alicia St Rose
Alicia St RoseFlag for United States of America

asked on

Trying to append content to Short Description in WooCommerce

Hello!

I'm trying to add some content to the short description in the single product view. I've created a div that contains Post Objects from an Advanced Custom Fields Post Object field.

I've got the code below, but instead of appending, it's actually replacing. I can see why, but I can't figure out how to bring back the summary in the code.

<?php add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
	$post_objects = get_field( 'juices_included_in_the_cleanse' );
			if ( $post_objects ): ?>
				<div class="cleanse-juices">
					<ul>
			
			 
				<?php foreach ( $post_objects as $post ):  ?>
					<?php setup_postdata( $post ); ?>
					<li>
						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
					</li>
				<?php endforeach; ?>
				<?php wp_reset_postdata(); ?>
			 </ul>
			<?php endif; ?>
		</div>
	</div>
  
<?php }
?>

Open in new window

SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Alicia St Rose

ASKER

Hi This is working, however, I'm only seeing the name of the actual post listed three times no matter how many or what juices I add in the Post Object custom field. Not sure what going wrong..

User generated image
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Here's a snapshot of my ACF settings

User generated image
I just added your new code, correctly and it worked.
OK. That all looks OK. Now on a particular product page, make sure you've selected some Posts that have the correct titles you want to display. Then test the new code I've posted. The code should work, but it looks like you've just selected additional products that have the same title, which is why you're seeing the same title several times.
Ah. Brilliant :)

Glad it's working
Actually, they were all different, but were somehow pulling in the current product/post title instead of the post objects I'd selected.

Now, I've got to remove the list from the Variation Description. Looks like the description hook works on both...

User generated image
I may just do a display: none; on that one!
Hey Alicia,

I think you have too. Just done a quick search and it looks like a bug in WooCommerce. The solutions provided seem to suggest hiding it with CSS. Not ideal, but it should work fine.
Ah, good to know!