Activate ratings for all products programmatically with the following code:
add_action('admin_init', 'cwhf_enable_reviews');
function cwhf_enable_reviews() {
$args = array(
'post_type' => 'product',
'numberposts' => -1,
'comment_status' => 'closed',
'post_status' => 'publish',
);
$shop_products = get_posts( $args );
foreach( $shop_products as $item){
$product = new WC_Product($item->ID);
wp_update_post( array(
'ID' => $item->ID,
'comment_status' => 'open',
) );
}
}
Paste this code into functions.php or use it as a plugin and open the admin panel once. This activates ratings (reviews) for all products. Afterwards, the code should be removed again. This is only necessary once.
In order for ratings to be automatically enabled for new products, a checkmark must be placed next to“Allow visitors to comment on new posts” under Settings -> Discussion.
You have more questions about WooCommerce or need support? We will be happy to help you. Get a quote to help you with your WooCommerce store.