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.
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.
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.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

