Display WooCommerce product attribute on shop page

Question

I am trying to show the attribute of Applications with the word Applications in front of the items that it echos. The code is working for me to echo the items out but I need it so that it only shows the text Applications when there are some with that product.

add_action( 'woocommerce_after_shop_loop_item_title', 'display_applications_attribute', 5 );
function display_applications_attribute() {
    global $product;

    
        $taxonomy = 'pa_applications';
        echo '<span class="attribute-applications">Applications: ' . $product->get_attribute($taxonomy) . '</span>';
    }


0
Sdesign 4 months 0 Answers 9 views 0

Leave an answer