WooCommerce Cart Minimum Plugin

This WordPress plugin adds a minimum cart total requirement to WooCommerce stores. It hooks into WooCommerce settings to allow site administrators to define a minimum order total and displays a notice to customers if their cart total does not meet this requirement, preventing them from proceeding to checkout until the minimum is met.

<?php /** * Plugin Name: WooCommerce Cart Minimum * Plugin URI: * Author: CodeWP Assistant * Author URI: * Description: This plugin adds a mandatory minimum amount for WooCommerce cart and prevents checkout if the minimum isn't met. */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } class WC_Cart_Minimum { const SETTING_ID = 'wc_setting_cart_minimum'; public function __construct() { add_filter('woocommerce_general_settings', array($this, 'add_cart_minimum_setting')); add_action('woocommerce_checkout_process', array($this, 'validate_cart_minimum_on_checkout')); add_action('woocommerce_proceed_to_checkout', array($this, 'validate_cart_minimum'), 20); add_action('woocommerce_review_order_before_submit', array($this, 'validate_cart_minimum'), 20); } public function add_cart_minimum_setting($settings) { $settings[] = array( 'id' => self::SETTING_ID, 'title' => __('Cart minimum', 'codewp'), 'desc_tip' => __('This is the minimum cart total required to proceed to checkout.', 'codewp'), 'type' => 'number', ); return $settings; } public function validate_cart_minimum() { $cart_minimum = get_option(self::SETTING_ID); if (WC()->cart->total < $cart_minimum) { wc_print_notice( sprintf( __('Your current order total is %s — you must have an order with a minimum of %s to place your order', 'codewp'), wc_price(WC()->cart->total), wc_price($cart_minimum) ), 'error' ); } } // Added function to handle checkout validation public function validate_cart_minimum_on_checkout() { $cart_minimum = get_option(self::SETTING_ID); if (WC()->cart->total < $cart_minimum) { wc_add_notice( sprintf( __('Your current order total is %s — you must have an order with a minimum of %s to proceed to checkout', 'codewp'), wc_price(WC()->cart->total), wc_price($cart_minimum) ), 'error' ); } } } new WC_Cart_Minimum();

Frequently Asked Questions

It's a plugin that sets a minimum cart total for WooCommerce, preventing checkout if the minimum isn't met.