Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce Enable Reviews - Bulk Edit
<?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();
}
@spigotdesign

This comment has been minimized.

Copy link

@spigotdesign spigotdesign commented Nov 20, 2018

Thanks Mario!

@xrahat2011

This comment has been minimized.

Copy link

@xrahat2011 xrahat2011 commented Jan 26, 2019

Still works with WordPress 5.0.3 on 26 Jan, 2019 -> AMAZING!

@takaacstamaas

This comment has been minimized.

Copy link

@takaacstamaas takaacstamaas commented Oct 15, 2019

Working great on WP 5.2, Thanks!

@mariovalney

This comment has been minimized.

Copy link
Owner Author

@mariovalney mariovalney commented Oct 15, 2019

Thanks for your feedback @xrahat2011 and @takaacstamaas

@Red-N-Dusty

This comment has been minimized.

Copy link

@Red-N-Dusty Red-N-Dusty commented Jan 31, 2020

Fantastic plugin @mariovalney. It really helped me out updating nearly 1,300 products.

@mariovalney

This comment has been minimized.

Copy link
Owner Author

@mariovalney mariovalney commented Jan 31, 2020

Nice to hear that @Red-N-Dusty ! Thanks for your feedback.

@adamn1225

This comment has been minimized.

Copy link

@adamn1225 adamn1225 commented Jun 26, 2020

Life saver

@fatihtoprak

This comment has been minimized.

Copy link

@fatihtoprak fatihtoprak commented Nov 11, 2020

Awesome thanks.

@mariovalney

This comment has been minimized.

Copy link
Owner Author

@mariovalney mariovalney commented Nov 11, 2020

Nice to know it's still useful 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.