How to delete WooCommerce categories in bulk that only have one product

Something like this, I believe:

$args = array(
'number' => -1,
'hide_empty' => false
);
$product_categories = get_terms( 'product_cat', $args );
foreach( $product_categories as $cat ) {
if ( $cat->count <=1 ) {
wp_delete_term( $cat->term_id );
}
}