Advertisement
daymobrew

CMB2 - trying to save to custom table

Aug 21st, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | Source Code | 0 0
  1. <?php
  2.  
  3. add_filter( 'cmb2_override_meta_value', 'dcwd_cmb2_override_meta_value', 10, 4 );
  4. //add_filter( 'cmb2_override_tracking_number_meta_value', 'dcwd_cmb2_override_meta_value', 10, 4 );
  5. function dcwd_cmb2_override_meta_value( $type, $object_id, $a, $this_obj ) {
  6.     error_log( 'Type: '. $type );
  7.     error_log( 'Post/object ID: '. $object_id );
  8.     error_log( '$a: '. var_export( $a, true ) );
  9.  
  10.     return 'cmb2_field_no_override_val';
  11. }
  12.  
  13.  
  14. add_filter( 'cmb2_override_meta_save', 'dcwd_cmb2_override_meta_save', 10, 4 );
  15. add_filter( 'cmb2_override_tracking_number_meta_save', 'dcwd_cmb2_override_meta_save', 10, 4 );
  16. add_filter( 'cmb2_override_tracking_url_meta_save', 'dcwd_cmb2_override_meta_save', 10, 4 );
  17. function dcwd_cmb2_override_meta_save( $override, $a, $args, $this_obj ) {
  18.     error_log( 'Type: cmb2_override_*' . $a['field_id'] . '*_meta_save' );
  19.     error_log( '$a: '. var_export( $a, true ) );
  20.     error_log( '$_POST: '. var_export( $_POST, true ) );
  21.    
  22.     return $override;
  23. }
  24.  
  25.  
  26. add_filter( 'cmb2_can_save', 'dcwd_cmb2_can_save', 10, 2 );
  27. function dcwd_cmb2_can_save( $can_save, $cmb_obj ) {
  28.     $current_screen = get_current_screen();
  29.    
  30.     if ( 'woocommerce_page_wc-orders' == $current_screen->id ) {
  31.         if ( array_key_exists( 'tracking_number', $_POST ) && ( !empty( $_POST[ 'tracking_number' ] ) ) ) {
  32.             if ( array_key_exists( 'tracking_url', $_POST ) && ( !empty( $_POST[ 'tracking_url' ] ) ) )
  33.                 error_log( 'dcwd_cmb2_can_save: Return true as tracking_number and tracking_url are in $_POST.' );
  34.                 return true;
  35.         }
  36.     }
  37.  
  38.     return $can_save;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement