Add Minimum Order Message for Discount in WooCommerce

How to add message for minimum order discount in woocommerce; Woocommerce minimum order message for discount; Set up minimum order alert for discount woocommerce; Woocommerce plugin for minimum order discount message; Add notification for minimum order discount in wordpress; Minimum order discount message woocommerce setup; How to notify customers of minimum order discount woocommerce; Woocommerce alert for minimum order discount; Configure minimum order discount message in wordpress; Wordpress plugin for minimum order discount notification;

Explanation

Want to let your customers know how close they are to getting a discount? This snippet does just that in WooCommerce!

Here's how it works:

  • Minimum Order Amount: You set a specific amount that customers need to spend to qualify for a discount. In the code, it's set to $50, but you can change it to whatever suits your store.
  • Cart Total: The code checks how much your customer has in their cart.
  • Message Display: If the cart total is less than the minimum amount, a friendly message pops up. It tells customers how much more they need to spend to get that sweet discount.

This message appears on both the cart and checkout pages, encouraging customers to add a little more to their cart to save money. Just adjust the minimum order amount to fit your needs, and you're good to go!

Code

<?php
// Add a custom message for minimum order discount in WooCommerce

function wp_dudecom_add_minimum_order_discount_message() {
    // Set the minimum order amount required for discount
    $minimum_order_amount = 50; // Change this to your desired minimum order amount

    // Get the current cart total
    $cart_total = WC()->cart->get_cart_contents_total();

    // Check if the cart total is less than the minimum order amount
    if ( $cart_total < $minimum_order_amount ) {
        // Calculate the remaining amount needed to reach the minimum order
        $remaining_amount = $minimum_order_amount - $cart_total;

        // Display the custom message
        wc_print_notice(
            sprintf(
                __('Spend an additional %s to receive a discount on your order!', 'woocommerce'),
                wc_price($remaining_amount)
            ),
            'notice'
        );
    }
}
add_action('woocommerce_before_cart', 'wp_dudecom_add_minimum_order_discount_message');
add_action('woocommerce_before_checkout_form', 'wp_dudecom_add_minimum_order_discount_message');
?>

Instructions

File Location: functions.php or a custom plugin file.

Prerequisites:

  • Ensure WooCommerce is installed and activated on your WordPress site.

Implementation Steps:

  1. Access your WordPress admin dashboard.
  2. Navigate to Appearance > Theme Editor if you are editing the functions.php file, or go to Plugins > Editor if you are using a custom plugin file.
  3. Locate the functions.php file of your active theme or the custom plugin file where you want to add the code.
  4. Copy the provided code snippet.
  5. Paste the code into the functions.php file or the custom plugin file.
  6. Adjust the $minimum_order_amount variable to your desired minimum order amount if different from $50.
  7. Save the changes to the file.
  8. Visit your WooCommerce cart or checkout page to verify that the message appears when the cart total is below the specified minimum order amount.

If you need assistance with this implementation or require more advanced functionality, consider reaching out to wp-dude.com for expert help.