Snippet

Add Minimum Order Message for Discount in WooCommerce

How to add message for minimum order discount in woocommerceWoocommerce minimum order message for discountSet up minimum order alert for discount woocommerceWoocommerce plugin for minimum order discount messageAdd notification for minimum order discount in wordpressMinimum order discount message woocommerce setupHow to notify customers of minimum order discount woocommerceWoocommerce alert for minimum order discountConfigure minimum order discount message in wordpressWordpress 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

1<?php 2// Add a custom message for minimum order discount in WooCommerce 3 4function wp_dudecom_add_minimum_order_discount_message() { 5 // Set the minimum order amount required for discount 6 $minimum_order_amount = 50; // Change this to your desired minimum order amount 7 8 // Get the current cart total 9 $cart_total = WC()->cart->get_cart_contents_total(); 10 11 // Check if the cart total is less than the minimum order amount 12 if ( $cart_total < $minimum_order_amount ) { 13 // Calculate the remaining amount needed to reach the minimum order 14 $remaining_amount = $minimum_order_amount - $cart_total; 15 16 // Display the custom message 17 wc_print_notice( 18 sprintf( 19 __('Spend an additional %s to receive a discount on your order!', 'woocommerce'), 20 wc_price($remaining_amount) 21 ), 22 'notice' 23 ); 24 } 25} 26add_action('woocommerce_before_cart', 'wp_dudecom_add_minimum_order_discount_message'); 27add_action('woocommerce_before_checkout_form', 'wp_dudecom_add_minimum_order_discount_message'); 28?>

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.