mbcreation

Untitled

Feb 16th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. //functions.php file in your theme
  2.  
  3. //1. First, add a new column "custom". It has to be named : '_custom_key_' followed by whatever your want (no spaces.)
  4. // for exemple : _custom_key_whatever
  5.  
  6. function my_custom_csv_columns($keys)
  7. {
  8.     $keys[] = '_custom_key_note';
  9.     return $keys;
  10. }
  11.  
  12. add_filter( 'wqep_included_order_keys_filter', 'my_custom_csv_columns' );
  13.  
  14. //2. Then, populate the columns with the data you want (for example, several post meta concatenated)
  15. // The first parameter to add_filter must be 'wqep_order' followed by the column key. For this example : 'wqep_order_custom_key_whatever'
  16.  
  17. add_filter( 'wqep_order_custom_key_note', 'my_custom_key_note', 10, 2 );
  18.  
  19. function my_custom_key_note($val, $order)
  20. {
  21.     //set $val to whatever you want. $order is a WC_Order object, id is $order->id
  22.         // for example retrieve a post meta of the order
  23.  
  24.     remove_filter('comments_clauses', array( 'WC_Comments' ,'exclude_order_comments'), 10, 1 );
  25.  
  26.     $args = array(
  27.         'post_type' => 'shop_order',
  28.         'post_id' => $order->id,
  29.         'type' => 'order_note',
  30.     );
  31.    
  32.     $notes = get_comments( $args );
  33.  
  34.     for ($i=0; $i < count($notes) ; $i++) {
  35.         if( preg_match('/AuthNumber=[0-9]{7}/', $notes[$i]->comment_content, $matches ) ){
  36.            
  37.             return substr( $matches[0], -7 );
  38.        
  39.         }
  40.     }
  41.  
  42.     return '';
  43. }
Advertisement
Add Comment
Please, Sign In to add comment