Get attribute value using a shortcode on woocommerce


Your help is a lot appreciated, I’m trying to create a shortcode to parse a single product attribute in description texts, for example :

“Please check the size guide, we use (display_attribute attribute=”origin”) size standard

and the attribute shortcode is replaced with whatever value we have assigned to that product.

I tried tampering with the following code but the output is always blank :

function so_39394127_singular_attribute_shortcode( $atts ) {
    global $product;
    if( ! is_object( $product ) || ! $product->has_attributes() ){
        return;
    }
    // parse the shortcode attributes
    $args = shortcode_atts( array(
        'attribute' => ''
    ), $atts );
    // start with a null string because shortcodes need to return not echo a value
    $html = '';
    if( $args('attribute') ){
        // get the WC-standard attribute taxonomy name
        $taxonomy = strpos( $args('attribute'), 'pa_' ) === false ? wc_attribute_taxonomy_name( $args('attribute') ) : $args('attribute');
        if( taxonomy_is_product_attribute( $taxonomy ) ){
            // Get the attribute label.
            $attribute_label = wc_attribute_label( $taxonomy );
            // Build the html string with the label followed by a clickable list of terms.
            // Updated for WC3.0 to use getters instead of directly accessing property.
            $html .= get_the_term_list( $product->get_id(), $taxonomy, $attribute_label . ': ' , ', ', '' );   
        }
    }
    return $html;
}
add_shortcode( 'display_attribute', 'so_39394127_singular_attribute_shortcode' );

Is there something I’m missing ?

Thank you for your assistance