add_filter( 'woocommerce_post_class', function( $classes, $product ) {
// Variations Yield To Parent Product IDs
if( $product->is_type( 'variation' ) ) {
$product = wc_get_product( $product->get_parent_id() );
}
// Add Product Attribute
$attribute_slug = 'country-of-origin';
$coo = $product->get_attribute( 'pa_' . $attribute_slug );
if( $coo ) {
$classes[] = 'pa_' . $attribute_slug . '-' . sanitize_title( $coo );
}
// Return
return $classes;
}, 10, 2 );
// Blocks Support
add_filter( 'wp_get_attachment_image_attributes', function( $attr) {
if( ! class_exists( 'WooCommerce' ) ) {
return $attr;
}
if( is_product() || is_shop() || is_product_category() ) {
global $product;
if( $product ) {
$attribute_slug = 'country-of-origin';
$coo = $product->get_attribute( 'pa_' . $attribute_slug );
if( $coo ) {
$attr['class'] .= ' pa_' . $attribute_slug . '-' . sanitize_title( $coo );
}
}
}
return $attr;
} );
CSS example:
.wc-block-components-product-image a:has(img.pa_country-of-origin-usa):before,
body.pa_country-of-origin-usa div.woocommerce-product-gallery:before {
content: url( '/wp-content/uploads/2025/09/MADE_IN_USA-150x150.png' ) / "Made in USA";
position: absolute;
display: inline-block;
transform: scale( .5 );
z-index: 1;
top: -50px;
left: -50px;
}