Tagged: x
-
AuthorPosts
-
March 27, 2017 at 5:24 am #1421429
Hi there!
I have been going through this thread https://community.theme.co/forums/topic/woocommerce-displaying-inventory-amount-and-short-description-on-shop-page/ and took the very first code section on that page:
//Add excerpt to archive pages add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 ); function output_product_excerpt() { global $post; echo $post->post_excerpt; } //Add stock status to archive pages function envy_stock_catalog() { global $product; if ( $product->is_in_stock() ) { echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>'; } else { echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>'; } } add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
It works fine, except i would like to restrict the excerpt to a limited number of characters…. How should I do that?
Kind regards, Tristan
March 27, 2017 at 5:26 am #1421432This reply has been marked as private.March 27, 2017 at 5:38 am #1421441Please note also that with .woocommerce .entry-wrap {box-shadow: none;} i have been able to remove the box shadow sitting between the product title/price and description.
However, I would also like to manipulate the text of that short description: Reduce the font size, and add some padding, so the text doesn’t hit the borders of the .entry-product div?
March 27, 2017 at 6:25 am #1421478Hi,
You can change your code to this.
//Add excerpt to archive pages add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 ); function output_product_excerpt() { global $post; echo word_limiter($post->post_excerpt,20); }
Change 20 to adjust the excerpt length.
Then to adjust the font size, you can add this in Custom > Edit Global CSS
.archive.woocommerce .product .entry-product { font-size: 14px; padding:10px 10px 10px; }
Hope that helps.
March 27, 2017 at 6:44 am #1421498Thanks, but that code doesn’t work.
When i replace `//Add excerpt to archive pages
add_action( ‘woocommerce_after_shop_loop_item_title’, ‘output_product_excerpt’, 35 );
function output_product_excerpt() {
global $post;
echo $post->post_excerpt;
}`with
//Add excerpt to archive pages add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 ); function output_product_excerpt() { global $post; echo word_limiter($post->post_excerpt,20); }
the shop page only displays one product, and without the description…?
March 27, 2017 at 6:54 am #1421506Also please notice that
.archive.woocommerce .product .entry-product { font-size: 14px; padding:10px 10px 10px; }
changes the padding of the entire .entry-product, which is not what i intent to do. It increases the spacing between the products on the shoppage.
Rather, i would like to have some white space around the description text, but not alter the size of the .entry product. I hope i explained it better.
March 27, 2017 at 9:06 am #1421642Hi,
In that case, you may change the php code to this.
//Add excerpt to archive pages add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 20 ); function output_product_excerpt() { global $post; echo '<div class="my-excerpt">'.wp_trim_words($post->post_excerpt,20).'</div>'; }
Then change the css code to this.
.my-excerpt { padding:20px; }
Hope that helps
-
AuthorPosts