How to Automatically Tag WooCommerce Customers as B2B or B2C

Want to automatically tag WooCommerce customers as B2B or B2C based on whether they fill in a company name at checkout?

This quick tutorial shows you how to set it up using a simple code snippet and Noptin.

What You Need

  • At least version 3.0 of WooCommerce.
  • At least version 3.5 of Noptin.
  • (Optional) Enable the Noptin and WooCommerce integration to collect subscribers before tagging them since the below code snippet does not collect new subscribers. It just tags them.

Step 1: Add the Code Snippet

Add this PHP code snippet to your site.

<?php
add_action( 'woocommerce_checkout_order_processed', 'tag_b2b_or_b2c_customer' );
add_action( 'woocommerce_store_api_checkout_order_processed', 'tag_b2b_or_b2c_customer' );

function tag_b2b_or_b2c_customer( $order_id ) {
    $order = wc_get_order( $order_id );
    if ( ! $order ) return;

    $email = $order->get_billing_email();
    $company = $order->get_billing_company();

    // Try to get the Noptin subscriber by email
    $subscriber = noptin_get_subscriber( $email );
    if ( ! $subscriber->exists() ) return;

    // Determine the tag
    $tag_to_add = empty( $company ) ? 'B2C' : 'B2B';
    $tag_to_remove = empty( $company ) ? 'B2B' : 'B2C';

    // Update tags
    $subscriber->set( 'tags::add', $tag_to_add );
    $subscriber->set( 'tags::remove', $tag_to_remove );
    $subscriber->save();
}

Step 2: Test Your Checkout

Place a test order:

  • With a company name, Noptin should tag the subscriber as B2B.
  • Without a company name, Noptin should tag the subscriber as B2C.

Check the subscriber record in Noptin > Subscribers to confirm the tag was added correctly.

Auto-tag customers in WooCommerce checkout

Wrap Up

This automation makes it easy to segment your B2B or B2C marketing audience. Once tagged, you can send targeted emails or add them to different sequences in Noptin.

FAQ

Here are some of the answers to our frequently asked questions

Noptin is an email marketing automation plugin for WordPress.

It’s lightweight, fast, and easy to use, making it a great solution for bloggers, small businesses, and e-commerce websites.

No coding skills required! Noptin’s drag-and-drop editor makes it easy for anyone to customize this template.

Simply click on any element to edit text, change colors, or upload your own images.

Yes! This email template works independently of your WordPress theme.

It’s designed to be sent as an email, not displayed on your website, so it’s compatible with any WordPress setup.

Yes, this template is fully responsive and optimized for all devices. Your emails will look great whether your subscribers open them on desktop, tablet, or mobile.

Faith Wavinya

Still have questions?

Can’t find what you’re looking for? Let’s have a chat!