I have created code as below and the focus part is PM.meta_key !='_price' and I don't know how true it is, it didn't work but it's also possible to remove all products otherwise, I need a correct way.
Also here is a picture, some products don't have the "_price" key and this way the product looks very bad, the strange thing is that they are still in stock.
Here is an example photo.
add_action( 'init', 'automatically_trash_instock_empty_price' );
function automatically_trash_instock_empty_price() {
// Get any existing copy of our transient data
if ( false === ( $automatically_trash_instock_empty_price = get_transient( 'automatically_trash_instock_empty_price' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->posts} P JOIN {$wpdb->postmeta} PM ON P.ID = PM.post_id SET P.post_status='trash' WHERE P.post_type='product' and PM.meta_key != '_price'" );
set_transient( 'automatically_trash_instock_empty_price', true, 1 * HOUR_IN_SECONDS );
}
}
