Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Offer BOGO Deals Based on Customer Email Domain in WooCommerce?

Offering BOGO offers to selected email domains gives a sense of exclusivity to those customers who are part of that email domain. For instance, you might decide to reward customers from corporate domains like ‘@companyname.com’ with a complimentary product when they make a purchase. Such WooCommerce BOGO deals on targeted email domains not only make the client feel valued but also encourage repeat business.

Solution: Offer BOGO Deals Based on Customer Email Domain in WooCommerce

The code snippet will provide BOGO deals by email domain of the customers. Additionally, the code also sends an email notification about the added free gift.

function ts_check_and_notify_free_product_added( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
    // Define the allowed email domains
    $allowed_email_domains = array( 'gmail.com', 'yahoo.com' );

    // Get the user's email address
    $user_id = get_current_user_id();
    $user_email = get_userdata($user_id)->user_email;

    // Define the free product ID
    $free_product_id = 470;

    // Check if the free product is not already in the cart and another product is being added
    if (!ts_wc_find_product_in_cart($free_product_id) && !empty(WC()->cart->get_cart_contents())) {
        // Add the free product to the cart
        WC()->cart->add_to_cart($free_product_id, 1);

        // Send email notification
        $to = $user_email;
        $subject = 'Free Product Added to Your Cart';
        $message = 'Hello, 
                    The free product with ID ' . $free_product_id . ' has been added to your cart. 
                    Thank you for shopping with us!';
        
        // Display a notice to the user
        wc_add_notice('Congratulations! You have received a free product. Check your cart for details.', 'success');
        
        // Send email
        wp_mail($to, $subject, $message);
    }
}

add_action('woocommerce_add_to_cart', 'ts_check_and_notify_free_product_added', 10, 6);

// Helper function to find a product in the cart
function ts_wc_find_product_in_cart($product_id) {
    foreach (WC()->cart->get_cart() as $cart_item) {
        if ($product_id == $cart_item['product_id']) {
            return true;
        }
    }
    return false;
}

// Helper function to check if an email address has an allowed domain
function ts_email_has_allowed_domain($email, $allowed_domains) {
    $domain = substr(strrchr($email, "@"), 1);
    return in_array($domain, $allowed_domains);
}
flexi bogo cta banner image


This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…

BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?

Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.

Output

Let’s say when a customer logs in from a particular email domain such as ‘@gmail.com’, and then adds any product to the cart, the free product is automatically added to the cart. In case of logging in using any other email domain, the free product will not be offered.

BOGO Deals Based on Customer Email Domain

The customer also receives an email notification about the details of the added free gift as shown below.

How to Offer BOGO Deals Based on Customer Email Domain in WooCommerce? - Tyche Softwares

Just like this you can observe the pattern of customer behavior and offer personalized bogo offers for high valued customers in WooCommerce who were partners in your journey of growth

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x