Advertisement
verygoodplugins

Untitled

Aug 8th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. function add_member_field( $meta_fields ) {
  2.  
  3.     $meta_fields['member_bought'] = array( 'label' => 'Member Bought', 'group' => 'woocommerce' );
  4.  
  5.     return $meta_fields;
  6.  
  7. }
  8.  
  9. add_filter( 'wpf_meta_fields', 'add_member_field' );
  10.  
  11. function get_member_data( $order_data, $order ) {
  12.  
  13.     foreach ( $order->get_items() as $item ) {
  14.  
  15.         $product_id = $item->get_product_id();
  16.  
  17.         $product_terms = get_the_terms( $product_id, 'product_cat' );
  18.  
  19.         foreach ( $product_terms as $term ) {
  20.  
  21.             if ( $term->slug == 'membership' ) {
  22.  
  23.                 $order_data['member_bought'] = 'YES';
  24.  
  25.                 break 2;
  26.  
  27.             }
  28.  
  29.         }
  30.  
  31.     }
  32.  
  33.     return $order_data;
  34.  
  35. }
  36.  
  37. add_filter( 'wpf_woocommerce_customer_data', 'get_member_data', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement