How to Implement Referrer-Based Pricing in WooCommerce – 2026

Last updated on July 18th, 2024 at 11:01 am

Implementing referrer-based pricing in WooCommerce can help tailor your store’s prices based on where your customers are coming from. This strategy can be particularly useful for running promotions through specific channels or providing exclusive discounts to customers arriving from partner sites. In this post, we will show you how to set up referrer-based pricing in WooCommerce without using a plugin.

By the end of this guide, you will have a system in place that adjusts product prices based on the referrer URL. This can enhance your marketing efforts and improve conversion rates by offering targeted discounts.

Step 1: Detecting the Referrer

First, we need to detect the referrer and store it in a session variable. Add the following code to your theme’s functions.php file.

/*
 * Snippet: How to Implement Referrer-Based Pricing in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1259
* Tested with WooCommerce 10.7.0
* "Detect the referrer and store in session"
*/ add_action('init', 'wcsuccess_store_referrer_in_session'); function wcsuccess_store_referrer_in_session() { if (!session_id()) { session_start(); } if (isset($_SERVER['HTTP_REFERER']) && !isset($_SESSION['referrer'])) { $_SESSION['referrer'] = $_SERVER['HTTP_REFERER']; } }

This code checks if there is a referrer URL and stores it in the session if it hasn’t been set already.

Step 2: Implementing Referrer-Based Pricing

Next, we will adjust the product prices based on the referrer URL. Add the following code to your functions.php file.

/*
 * Snippet: How to Implement Referrer-Based Pricing in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1259
* Tested with WooCommerce 10.7.0
* "Adjust prices based on referrer"
*/ function wcsuccess_referrer_based_pricing($price, $product) { if (isset($_SESSION['referrer'])) { $referrer = $_SESSION['referrer']; // Example: Apply a 10% discount for visitors coming from example.com if (strpos($referrer, 'example.com') !== false) { return $price * 0.90; } // Example: Apply a 15% discount for visitors coming from partner.com if (strpos($referrer, 'partner.com') !== false) { return $price * 0.85; } } return $price; } add_filter('woocommerce_product_get_price', 'wcsuccess_referrer_based_pricing', 30, 2); add_filter('woocommerce_product_variation_get_price', 'wcsuccess_referrer_based_pricing', 30, 2);

This code adjusts the product price based on the referrer. You can add more conditions to cater to different referrers.

See also  How To Add A Checkbox To Woocommerce Checkout Page

Step 3: Displaying Discount Information

To inform customers about the discount they’re receiving based on the referrer, you can display a custom message on the product page. Add the following code to your functions.php file.

/*
 * Snippet: How to Implement Referrer-Based Pricing in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1259
* Tested with WooCommerce 10.7.0
* "Display discount information"
*/ function wcsuccess_display_referrer_discount_info() { if (isset($_SESSION['referrer'])) { $referrer = $_SESSION['referrer']; if (strpos($referrer, 'example.com') !== false) { echo '<p class="woocommerce-discount-info">Exclusive 10% discount for visitors from Example.com!</p>'; } if (strpos($referrer, 'partner.com') !== false) { echo '<p class="woocommerce-discount-info">Exclusive 15% discount for visitors from Partner.com!</p>'; } } } add_action('woocommerce_single_product_summary', 'wcsuccess_display_referrer_discount_info', 20);

This code displays a message on the product page indicating the discount applied based on the referrer.

Step 4: Styling the Discount Information

To ensure the discount information is styled appropriately, add the following CSS to your theme’s customizer under Additional CSS.

/*
 * Snippet: How to Implement Referrer-Based Pricing in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1259
* Tested with WooCommerce 10.7.0
* "CSS for discount information"
*/ .woocommerce-discount-info { color: #ff0000; font-weight: bold; margin-top: 10px; }

This CSS styles the discount message to make it stand out on the product page.

Step 5: Testing and Debugging

After implementing the code, it’s essential to test the referrer-based pricing. Visit your WooCommerce store from the specified referrers (e.g., example.com and partner.com) and verify that the prices and discount messages are displaying correctly.

See also  How to Create New Hooks and Hook Locations for WooCommerce - 2026

Conclusion

Implementing referrer-based pricing in WooCommerce without using a plugin is a powerful way to offer targeted discounts and improve your marketing efforts. By following the steps outlined in this guide, you can create a dynamic pricing system that adjusts prices based on the referrer URL, providing a personalized shopping experience for your customers.

Feel free to customize the code snippets provided to fit your specific requirements. With this setup, you can enhance your promotional strategies and drive more conversions by offering exclusive deals to visitors from different referrer sources.

By leveraging referrer-based pricing, you can effectively target your marketing campaigns and reward your most valuable traffic sources with special offers, ultimately boosting your WooCommerce store’s performance.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×