L
L
lorab2022-03-13 16:25:54
WordPress
lorab, 2022-03-13 16:25:54

How to fix the code for displaying tags without errors?

there is a code, and it works fine on product pages that have tags filled in. But if the tags are not filled, it raises an error. Please tell me what's wrong? what needs to be fixed?

add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_loop_tags', 31 );
function woocommerce_product_loop_tags() {
    global $post, $product;

    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
    $idProducto=$product->id;
     $product->get_title();
    $product->get_tags( ', ', '<span class="tagged">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );

    $producto= wc_get_product( $idProducto );
    $Titulo=$producto->get_title();
    echo "  ".$product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yury Bondaruk, 2022-03-13
@lorab

if($product->get_tags) {
code to display tags
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question