Created
July 10, 2025 08:10
-
-
Save finalwebsites/3efcc80b18055c4560bff16fcb4bc2fc to your computer and use it in GitHub Desktop.
Add a minimum order message to the cart page in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // add this code to the functions.php file from your child theme | |
| add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); | |
| function wc_minimum_order_amount() { | |
| // Set this variable to specify a minimum order value | |
| $minimum = 250; | |
| $min_passed = true; | |
| $subtotal = WC()->cart->get_subtotal(); | |
| if ( $subtotal < $minimum ) { | |
| $min_passed = false; | |
| $text = sprintf( | |
| __('The minimum order amount of %s has not yet been reached. Your total is currently %s.', 'bootscore-sp'), | |
| wc_price( $minimum ), | |
| wc_price( $subtotal ) | |
| ); | |
| } | |
| if (!$min_passed) { | |
| if( is_cart() ) { | |
| wc_print_notice( $text , 'notice' ); | |
| } else { | |
| wc_add_notice( $text, 'notice' ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment