Why does this work for all my products... EXCEPT the first on the page?

Hi there!

I added the following code to my functions.php

//add excerpt
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
//read more
//Read More Button For Excerpt
function themeprefix_excerpt_read_more_link( $output ) {
	global $post;
	return $output . ' <a href="' . get_permalink( $post->ID ) . '" class="meerlezenlink" title="Meer over dit product">Meer over dit product...</a>';
}
add_filter( 'the_excerpt', 'themeprefix_excerpt_read_more_link' );

What this code does is add the product description to my archive pages, and a ‘read more’ like link.

Anyway, this all works fine. PS: If you check this out, you’ll notice that by way of CSS this appears only on hover. May change that though.

Here’s the problem. On all of my Woo archive pages this works. EXCEPT for the very first product on the page. Even though the content is actually there.

Would you have any idea what could be causing this??

Hello There,

Thanks for writing in! We cannot check your WP dashboard since the given credentials has a very limited privileges. Can you change the role and make it as an administrator? Meanwhile, you could try testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

Please let us know how it goes.

Thanks,

I gave admin rights. Tested for plugin conflicts but that did not seem to be the case…

BTW I gave the wrong code in the opening of the thread.

That php related to the read more link.

This is how the excerpt is added on the archive pages.

<?php function tutsplus_excerpt_in_product_archives() { the_excerpt(); } Together with a change in the content-product.php file: <?php /** * The template for displaying product content within loops * * This template can be overridden by copying it to yourtheme/woocommerce/content-product.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 3.0.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } global $product; // Ensure visibility if ( empty( $product ) || ! $product->is_visible() ) { return; } ?>
<li <?php post_class(); ?>>
	<?php
	/**
	 * woocommerce_before_shop_loop_item hook.
	 *
	 * @hooked woocommerce_template_loop_product_link_open - 10
	 */
	do_action( 'woocommerce_before_shop_loop_item' );

	/**
	 * woocommerce_before_shop_loop_item_title hook.
	 *
	 * @hooked woocommerce_show_product_loop_sale_flash - 10
	 * @hooked woocommerce_template_loop_product_thumbnail - 10
	 */
	do_action( 'woocommerce_before_shop_loop_item_title' );

	/**
	 * woocommerce_shop_loop_item_title hook.
	 *
	 * @hooked woocommerce_template_loop_product_title - 10
	 */
	do_action( 'woocommerce_shop_loop_item_title' );

	/**
	 * woocommerce_after_shop_loop_item_title hook.
	 *
	 * @hooked woocommerce_template_loop_rating - 5
	 * @hooked woocommerce_template_loop_price - 10
	 */
	do_action( 'woocommerce_after_shop_loop_item_title' );

	/** inserted for excerpt
    */
	add_action( 'woocommerce_after_shop_loop_item_title', 'tutsplus_excerpt_in_product_archives', 40 );


	/**
	 * woocommerce_after_shop_loop_item hook.
	 *
	 * @hooked woocommerce_template_loop_product_link_close - 5
	 * @hooked woocommerce_template_loop_add_to_cart - 10
	 */
	do_action( 'woocommerce_after_shop_loop_item' );
	?>
</li>

Hello There,

Thanks for updating in!

This line should only be added in your child theme’s functions.php file.

add_action( 'woocommerce_after_shop_loop_item_title', 'tutsplus_excerpt_in_product_archives', 40 );

I went ahead and fixed the issue. I commented out that line in content-product.php file and moved it to the functions.php file. The excerpt is now displaying in the front end.

If you need anything else we can help you with, don’t hesitate to open another thread.

Fantastic!!

You guys are the best!

Glad that we could be o f a help :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.