Enabling Permanent Checkmark Checks for All WooCommerce Products

I would like the checkbox to enable check forever for all existing products and for newly added products. I looked in the WooCommerce settings, but this is not possible. I have an internet search and I haven’t found anything.

How can I change the volume of all existing products to get feedback included ?

When we add a new product, it should also be automatically checked.

Is there any way to do this?
Is it possible?

Thanks in advance.

+4
source share
4

, . , , .

1. .php . . .

// Updating all products that have a 'comment_status' => 'closed' to 'open'

function updating_existing_products_once(){
    $args = array(
        // WC product post type
        'post_type'   => 'product',
        // all posts
        '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',
        ) );
    }
}
// After usage comment this line below
updating_existing_products_once();

2. , 'comment_status' = > 'closed' to 'open' ( WooCommerce)...

add_action('transition_post_status', 'creating_a_new_product', 10, 3);
function creating_a_new_product($new_status, $old_status, $post) {
    if( $old_status != 'publish' && $new_status == 'publish' && !empty($post->ID)  && in_array( $post->post_type, array( 'product') ) ) {
        if ($post->comment_status != 'open' ){
            $product = new WC_Product($post->ID);
            wp_update_post( array(
                'ID'    => $post->ID,
                'comment_status' => 'open',
            ) );
        }
    }
}

function.php ( ), .

.

+4

LoicTheAztec, " 1".

, :

global $wpdb;
$wpdb->query("UPDATE {$wpdb->posts} SET comment_status = 'open' WHERE post_type = 'product'");

comment_status post_status WHERE. , , , , comment_status, , .

functions.php, , :

// Commented out so it won't run
// global $wpdb;
// $wpdb->query("UPDATE {$wpdb->posts} SET comment_status = 'open' WHERE post_type = 'product'");
+3

, -, LoicTheAztec ( ). , jQuery " ". -, ! :-)

add_action( 'woocommerce_product_options_advanced', 'enable_reviews_by_default' );
function enable_reviews_by_default() {
?>
    <script>
        (function($){
            $('input[name=comment_status]').prop('checked', true);
        })(jQuery);
    </script>
<?php
}
0

().

https://developer.wordpress.org/reference/functions/comments_open/

, , :)

: !

add_filter ('comments_open', '__return_true');

0

Source: https://habr.com/ru/post/1653528/


All Articles