-
-
Save mariovalney/6000feabd5e8fff294ed971788944279 to your computer and use it in GitHub Desktop.
| <?php | |
| /** | |
| * | |
| * Plugin Name: WooCommerce Enable Reviews - Bulk Edit | |
| * Description: Allow enable reviews by bulk edit into WooCommerce | |
| * Version: 1.0.0 | |
| * Author: Mário Valney | |
| * Author URI: http://mariovalney.com | |
| * Text Domain: woo-enable-reviews-bulk-edit | |
| * | |
| */ | |
| add_action( 'woocommerce_product_bulk_edit_end', 'wcerbe_woocommerce_product_bulk_edit_end' ); | |
| function wcerbe_woocommerce_product_bulk_edit_end() { | |
| $output = '<label><span class="title">' . esc_html__( "Enable reviews", "woocommerce" ) . '?</span>'; | |
| $output .= '<span class="input-text-wrap"><select class="reviews_allowed" name="_reviews_allowed">'; | |
| $options = array( | |
| '' => __( '— No change —', 'woocommerce' ), | |
| 'yes' => __( 'Yes', 'woocommerce' ), | |
| 'no' => __( 'No', 'woocommerce' ), | |
| ); | |
| foreach ( $options as $key => $value ) { | |
| $output .= '<option value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</option>'; | |
| } | |
| $output .= '</select></span></label>'; | |
| echo $output; | |
| } | |
| add_action( 'woocommerce_product_bulk_edit_save', 'wcerbe_woocommerce_product_bulk_edit_save', 10, 1 ); | |
| function wcerbe_woocommerce_product_bulk_edit_save( $product ) { | |
| // Enable reviews | |
| if ( ! empty( $_REQUEST['_reviews_allowed'] ) ) { | |
| if ( 'yes' === $_REQUEST['_reviews_allowed'] ) { | |
| $product->set_reviews_allowed( 'yes' ); | |
| } else { | |
| $product->set_reviews_allowed( '' ); | |
| } | |
| } | |
| $product->save(); | |
| } |
Thanks a million for this, sill working!
woocommerce 5.3.0
wordpress 5.7.2
Still working 2022. Thank you
Updated 14/06/22
**Note: we have since found an issue - do not use if you have variations. It has wiped out part of our variations on some products. We have lost data that we're not sure how to get back. **
Previous comment.
Thanks Mario. Worked perfectly.
WP 5.9.3
Woocommerce 6.5.1
I have variations and haven't found any issue.
Amazing. It's working also I have variable product and no issue s with that.
Thank you...!
No longer works.
It works. I have just tested it on woocommerce v8.2.1
still works 🤌🏻 woo 8.6.1 version
No longer works. Looks like it does. Checkbox is there, but it doesn't actually make the change on the product pages.
silly question but I added the zip and see the plugin is activated but I do not see it on the side panel to run it.
It would be a lifesaver for me as this morning I woke up to all my items having the enable reviews tab toggled to off.
I figured it out :)
You are a life safer :)
Nice to know it's still useful 😃