Advertisement
wclovers

ADD PRODUCT TYPE TO BULK EDIT

Jan 11th, 2022
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. add_action( 'wcfm_product_bulk_edit_start', function() {
  2.     $product_types = apply_filters( 'wcfm_product_types', array(
  3.         ''          => __( '— No change —', 'wc-frontend-manager' ),
  4.         'simple'    => __( 'Simple Product', 'wc-frontend-manager' ),
  5.         'variable'  => __( 'Variable Product', 'wc-frontend-manager' ),
  6.         'grouped'   => __( 'Grouped Product', 'wc-frontend-manager' ),
  7.         'external'  => __( 'External/Affiliate Product', 'wc-frontend-manager' )
  8.     ) );
  9.  
  10.     if( count( $product_types ) == 0 ) {
  11.         $product_types = array( ''  => __( '— No change —', 'wc-frontend-manager' ) );
  12.     }
  13.  
  14.     ob_start();
  15.     ?>
  16.     <div class="inline-edit-group inline-edit-group-type">
  17.         <label>
  18.             <span class="wcfm_popup_label title"><?php _e( 'Type', 'wc-frontend-manager' ); ?></span>
  19.             <span class="input-text-wrap">
  20.                 <select class="change_product_type wcfm_popup_input change_to" name="_product_type">
  21.                 <?php
  22.                     foreach ( $product_types as $key => $value ) {
  23.                         echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
  24.                     }
  25.                 ?>
  26.                 </select>
  27.             </span>
  28.         </label>
  29.     </div>
  30.     <?php
  31.     echo ob_get_clean();
  32. } );
  33.  
  34. add_action( 'wcfm_product_bulk_edit_save', function( $product, $wcfm_bulk_edit_form_data ) {
  35.     if( isset( $wcfm_bulk_edit_form_data['_product_type'] ) && ! empty( $wcfm_bulk_edit_form_data['_product_type'] ) ) {
  36.         wp_set_object_terms( $product->get_id(), $wcfm_bulk_edit_form_data['_product_type'], 'product_type', false );
  37.     }
  38. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement