woocommerce offtopic - I can 't display product images based on the label

The task is as follows. We have a product card template in Elementor, we have products with tags. The task is to use the

The task is as follows. We have a product card template in Elementor, we have products with tags. The task is to use the Portfolio tool to display images of products that belong to the same label as the product that we visited.

I understand this can be done by creating a certain filter and adding it to the query id. I tried adding this code via snippet in Query ID in the Query field in the Portfolio block , but it doesn't work

 $output = array();

// get an array of the WP_Term objects for a defined product ID
$terms = wp_get_post_terms( get_the_id(), 'product_tag' );

// Loop through each product tag for the current product
if( count($terms) > 0 ){
    foreach($terms as $term){
        $term_id = $term->term_id; // Product tag Id
        $term_name = $term->name; // Product tag Name
        $term_slug = $term->slug; // Product tag slug
        $term_link = get_term_link( $term, 'product_tag' ); // Product tag link

        // Set the product tag names in an array
        $output[] = '<a href="'.$term_link.'">'.$term_name.'</a>';
    }
    // Set the array in a coma separated string of product tags for example
    $output = implode( ', ', $output );

    // Display the coma separated string of the product tags
    echo $output;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744647842a4585721.html

相关推荐

  • woocommerce offtopic - I can &#39;t display product images based on the label

    The task is as follows. We have a product card template in Elementor, we have products with tags. The task is to use the

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信