Encourage Reorders in WooCommerce: Add Buy Again and Apply Discount Automatically
Looking for a way to encourage customers to reorder products they’ve already purchased from your WooCommerce store? Adding a “Buy Again” button with a 5% discount for repeat purchases can be a powerful loyalty booster — and it doesn’t require any plugins!
In this guide, I’ll show you how to:
- Change the “Add to Cart” text to “Buy Again” if the user has purchased the product before.
- Automatically apply a 5% discount on those products during checkout.
- Reward loyal customers and increase repeat sales — automatically!
📌 Step 1: Change “Add to Cart” to “Buy Again” (if purchased)
Let’s start with a small UX touch — modifying the button text on product and shop pages:
add_filter( 'woocommerce_product_add_to_cart_text', 'buy_again_button_text' );
function buy_again_button_text( $text ) {
if ( ! is_user_logged_in() || ! is_product() && ! is_shop() ) {
return $text;
}
global $product;
$user_id = get_current_user_id();
// Fetch customer orders
$orders = wc_get_orders( array(
'limit' => -1,
'customer_id' => $user_id,
'status' => array( 'wc-completed', 'wc-processing' ),
) );
foreach ( $orders as $order ) {
foreach ( $order->get_items() as $item ) {
if ( $item->get_product_id() === $product->get_id() ) {
return __( 'Buy Again', 'your-textdomain' );
}
}
}
return $text;
}
✅ Result: Logged-in users who previously bought the product will now see “Buy Again” instead of “Add to Cart.”
💰 Step 2: Give a 5% Discount for Repeat Purchases
Let’s reward those loyal customers at checkout by detecting repeat purchases and applying a 5% discount dynamically.
Add this to your functions.php
or a custom plugin:
add_action( 'woocommerce_cart_calculate_fees', 'apply_buy_again_discount', 20 );
function apply_buy_again_discount( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
if ( ! is_user_logged_in() ) return;
$user_id = get_current_user_id();
$discount = 0;
// Get list of purchased product IDs
$orders = wc_get_orders( array(
'limit' => -1,
'customer_id' => $user_id,
'status' => array( 'wc-completed', 'wc-processing' ),
'return' => 'ids',
) );
$purchased_products = array();
foreach ( $orders as $order_id ) {
$order = wc_get_order( $order_id );
foreach ( $order->get_items() as $item ) {
$purchased_products[] = $item->get_product_id();
}
}
// Apply discount if product was previously purchased
foreach ( $cart->get_cart() as $cart_item ) {
$product_id = $cart_item['product_id'];
if ( in_array( $product_id, $purchased_products ) ) {
$line_total = $cart_item['line_total'];
$discount += $line_total * 0.05; // 5% off
}
}
if ( $discount > 0 ) {
$cart->add_fee( __( 'Repeat Purchase Discount', 'your-textdomain' ), -$discount );
}
}
✅ Result: If a customer adds a product they’ve already purchased, WooCommerce will automatically apply a 5% discount during checkout.
🔔 Bonus: Show a Friendly Notice
Let your customer know they’re getting a reward — add this message to the cart:
add_action( 'woocommerce_before_cart', 'show_repeat_purchase_notice' );
function show_repeat_purchase_notice() {
if ( is_user_logged_in() ) {
echo '<div class="woocommerce-info">You’re getting 5% off items you’ve purchased before 🎉</div>';
}
}
🎯 Why This Works
- Boosts Loyalty: Returning customers feel rewarded.
- No Coupons Needed: Clean, automatic experience.
- Easy to Extend: You can increase the discount, limit it to specific categories, or track how many repeat purchases are made.
💡 Want to Extend It?
Here are some bonus ideas:
- Apply a larger discount if they’ve bought the product more than once.
- Only apply the discount if they’re logged in for more than X days.
- Add a “Recently Purchased” section with quick reordering.
Let me know if you’d like help building any of those — or turning this into a full plugin with settings in the WordPress dashboard.
🚀 Final Thoughts
This lightweight customization is a great way to encourage repeat orders on your WooCommerce store — no plugins, no extra overhead. Just a few lines of well-placed PHP and a more engaging customer experience.
Have questions or want to build more WooCommerce automations? Drop them in the comments or shoot me a message — happy to help!
Leave a Reply