Woocommerce: Search by custom attribute

First verify your product attribute (meta_key) by running this query

Note: Change table prefix according to your wordpress database mine is
default wp_

SELECT * FROM wp_postmeta WHERE meta_key LIKE '%code%'; /* get attribute name example (_sku, _stock, _stock_status, height, width )*/

Now add this to your functions.php file

function Add_custom_search( $query ) 
{

if( ! is_admin() && $query->is_main_query() ) 
{
    if ( $query->is_search() ) 
    { 
        $meta_query = $query->get( 'meta_query' );
        $meta_query[] = array(
            'key'       => 'code', /* Product Attribute Meta key Here example (_sku, _stock, _stock_status, height, width ) */
            'value'     => $query->query['s'],
            'compare'   => 'LIKE'  
        );
        $query->set( 'meta_query', $meta_query );
    }
 }
}
add_action( 'woocommerce_product_query' , 'Add_custom_search' );