G
G
Grizar2019-09-03 23:48:46
WordPress
Grizar, 2019-09-03 23:48:46

How to remove the empty description field?

I put the tags wordpress and wookomers because the site is on this, and you can solve the problem in jerry java or php.
I Display in the product catalog a brief description of the goods with this

//Добавление краткого описания в каталоге товаров и оборачиваем в div
add_action( 'woocommerce_after_shop_loop_item_title', 'div_start_loop_product_block', 10 );
function div_start_loop_product_block() {
   echo '<div class="desc_01_product">';
}
add_action( 'woocommerce_after_shop_loop_item_title', 'add_short_description', 10 );
function add_short_description() {
    echo  the_excerpt().' <br> ';
}
add_action( 'woocommerce_after_shop_loop_item_title', 'div_end_loop_product_block', 10 );
function div_end_loop_product_block() {
   echo '</div><!-- /desc_01_product-->';
}
//

The trick is, if there is a short description in the product card, then it is displayed accordingly, and if it is not there, then an empty field is displayed in the catalog list.
The question is how can I make it so that if there is no short description, then it does not create a field in the product catalog list.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Grizar, 2020-04-16
@Grizar

In the line
echo the_excerpt().' <br> ';
you need to remove <br>
i.e. succeed
echo the_excerpt().' ';, then everything works.
Explanation:
because this code adds a value <br>to the short description line and outputs it accordingly

R
runprogr, 2019-09-03
@runprogr

add_action( 'woocommerce_after_shop_loop_item_title', 'add_short_description', 10 );
function add_short_description() {
   $excerpt = the_excerpt();
    if $excerpt !== "" {
        echo  $excerpt . ' <br> ';
    }
}

Should work

V
Valery, 2019-09-04
@Val_Ery_1

The trick is, if there is a short description in the product card, then it is displayed accordingly, and if it is not there, then an empty field is displayed in the catalog list.

This is not a trick, these are your div_start_loop_product_block and div_end_loop_product_block
Do as @runprogr wrote to you , comment the start and end functions. If necessary, insert your divs inside the if before and after the excerpt output.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question