• Resolved namutube

    (@namutube)


    Could you please help me, I would like to add a “Referred by” field to WooCommerce order list and display the referrer user ID (referrer_user_id).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author shalior

    (@shalior)

    Not tested but should work

    function wprc_add_referred_by_col_header_woocommerce( $columns ) {
    
    	$new_columns = array();
    
    	foreach ( $columns as $column_name => $column_info ) {
    
    		$new_columns[ $column_name ] = $column_info;
    
    		if ( 'order_total' === $column_name ) {
    			$new_columns['order_profit'] = __( 'Referred By' );
    		}
    	}
    
    	return $new_columns;
    }
    add_filter( 'manage_edit-shop_order_columns', 'wprc_add_referred_by_col_header_woocommerce', 20 );
    
    function wprc_fill_referred_by_col( $column ) {
    	global $post;
    
    	if ( 'invited_by' === $column ) {
    
    		$order    = wc_get_order( $post->ID );
    		$user_id = $order->get_customer_id();
    
    			$referrer_id = ( new WP_Refer_Code( $user_id ) )->get_referrer_id();
    			if ( empty( $referrer_id ) ) {
    				echo '';
    			}
    
    			$referrer_username = esc_html(get_userdata( $referrer_id )->user_login);
    			if ( current_user_can( 'edit_user', $referrer_id ) ) {
    				$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $referrer_id ) ) );
    				$edit      = "<strong><a href=\"{$edit_link}\">{$referrer_username}</a></strong>";
    			} else {
    
    				$edit = "<strong>{$referrer_username}</strong>";
    			}
    
    			echo $edit;
    	}
    }
    add_action( 'manage_shop_order_posts_custom_column', 'wprc_fill_referred_by_col' );
    Thread Starter namutube

    (@namutube)

    Thank you very much indeed!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Referred by to WooCommerce order list’ is closed to new replies.