With the following Code I get a Custom Product Attribute from WooCommerce.
Is this code compliant or could it be solved better?
Is the global inside the function used properly?
How can I extend the code so that if the product attribute mentioned is not present, a message "No Information on this Product" is displayed?
Functions.php
function single_atr() {
global $product;
$custom_attribute = $product->get_attribute( 'Color' );
echo $custom_attribute;
}
add_shortcode( 'single_atr', 'short_ single_atr');
Shortcode in Elementor:
[short_ single_atr]