Created
May 21, 2020 16:59
-
-
Save pavlo-bondarchuk/f6459368e9a330f52dd93214ea6228b0 to your computer and use it in GitHub Desktop.
WooCommerce Enable Reviews - Bulk Edit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * 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(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment